diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
commit | 5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch) | |
tree | 298c3d2f08bdfe5689998b11892d72a897985be1 /t/attributes/no_slot_access.t | |
download | Moose-tarball-master.tar.gz |
Moose-2.1405HEADMoose-2.1405master
Diffstat (limited to 't/attributes/no_slot_access.t')
-rw-r--r-- | t/attributes/no_slot_access.t | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/t/attributes/no_slot_access.t b/t/attributes/no_slot_access.t new file mode 100644 index 0000000..22405ba --- /dev/null +++ b/t/attributes/no_slot_access.t @@ -0,0 +1,87 @@ +use strict; +use warnings; + +{ + package SomeAwesomeDB; + + sub new_row { } + sub read { } + sub write { } +} + +{ + package MooseX::SomeAwesomeDBFields; + + # implementation of methods not called in the example deliberately + # omitted + + use Moose::Role; + + sub inline_create_instance { + my ( $self, $classvar ) = @_; + + "bless SomeAwesomeDB::new_row(), $classvar"; + } + + sub inline_get_slot_value { + my ( $self, $invar, $slot ) = @_; + + "SomeAwesomeDB::read($invar, \"$slot\")"; + } + + sub inline_set_slot_value { + my ( $self, $invar, $slot, $valexp ) = @_; + + "SomeAwesomeDB::write($invar, \"$slot\", $valexp)"; + } + + sub inline_is_slot_initialized { + my ( $self, $invar, $slot ) = @_; + + "1"; + } + + sub inline_initialize_slot { + my ( $self, $invar, $slot ) = @_; + + ""; + } + + sub inline_slot_access { + die "inline_slot_access should not have been used"; + } +} + +{ + package Toy; + + use Moose; + use Moose::Util::MetaRole; + + use Test::More; + use Test::Fatal; + + Moose::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { instance => ['MooseX::SomeAwesomeDBFields'] }, + ); + + is( exception { + has lazy_attr => ( + is => 'ro', + isa => 'Bool', + lazy => 1, + default => sub {0}, + ); + }, undef, "Adding lazy accessor does not use inline_slot_access" ); + + is( exception { + has rw_attr => ( + is => 'rw', + ); + }, undef, "Adding read-write accessor does not use inline_slot_access" ); + + is( exception { __PACKAGE__->meta->make_immutable; }, undef, "Inling constructor does not use inline_slot_access" ); + + done_testing; +} |