From: Dave Rolsky Date: Thu, 9 Jul 2009 12:18:54 +0000 (-0500) Subject: Tidied code X-Git-Tag: 0.88~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e91fda412ef42c37721b74d41e2527857a46cdb4;p=gitmo%2FMoose.git Tidied code --- diff --git a/t/020_attributes/028_no_slot_access.t b/t/020_attributes/028_no_slot_access.t index 70cf7d6..cb6efa3 100644 --- a/t/020_attributes/028_no_slot_access.t +++ b/t/020_attributes/028_no_slot_access.t @@ -1,78 +1,90 @@ #!/usr/bin/perl -package SomeAwesomeDB; +use strict; +use warnings; -sub new_row { } -sub read { } -sub write { } +{ + package SomeAwesomeDB; -package MooseX::SomeAwesomeDBFields; + sub new_row { } + sub read { } + sub write { } +} -use Moose::Role; +{ + package MooseX::SomeAwesomeDBFields; -sub inline_create_instance { - my ($self, $classvar) = @_; + # implementation of methods not called in the example deliberately + # omitted - "bless SomeAwesomeDB::new_row(), $classvar"; -} + use Moose::Role; -sub inline_get_slot_value { - my ($self, $invar, $slot) = @_; + sub inline_create_instance { + my ( $self, $classvar ) = @_; - "SomeAwesomeDB::read($invar, \"$slot\")"; -} + "bless SomeAwesomeDB::new_row(), $classvar"; + } -sub inline_set_slot_value { - my ($self, $invar, $slot, $valexp) = @_; + sub inline_get_slot_value { + my ( $self, $invar, $slot ) = @_; - "SomeAwesomeDB::write($invar, \"$slot\", $valexp)"; -} + "SomeAwesomeDB::read($invar, \"$slot\")"; + } -sub inline_is_slot_initialized { - my ($self, $invar, $slot) = @_; + sub inline_set_slot_value { + my ( $self, $invar, $slot, $valexp ) = @_; - "1"; -} + "SomeAwesomeDB::write($invar, \"$slot\", $valexp)"; + } -sub inline_initialize_slot { - my ($self, $invar, $slot) = @_; + sub inline_is_slot_initialized { + my ( $self, $invar, $slot ) = @_; - ""; -} + "1"; + } -sub inline_slot_access { - die "inline_slot_access should not have been used"; -} + sub inline_initialize_slot { + my ( $self, $invar, $slot ) = @_; -# implementation of methods not called in the example deliberately -# omitted + ""; + } -package Toy; + sub inline_slot_access { + die "inline_slot_access should not have been used"; + } +} -use Moose; -use Moose::Util::MetaRole; +{ + package Toy; -use Test::More tests => 3; -use Test::Exception; + use Moose; + use Moose::Util::MetaRole; -Moose::Util::MetaRole::apply_metaclass_roles - (for_class => __PACKAGE__, - instance_metaclass_roles => [ 'MooseX::SomeAwesomeDBFields' ]); + use Test::More tests => 3; + use Test::Exception; -lives_ok { - has lazy_attr => ( - is => 'ro', - isa => 'Bool', - lazy => 1, - default => sub { 0 }, + Moose::Util::MetaRole::apply_metaclass_roles( + for_class => __PACKAGE__, + instance_metaclass_roles => ['MooseX::SomeAwesomeDBFields'] ); -} "Adding lazy accessor does not use inline_slot_access"; -lives_ok { - has rw_attr => ( - is => 'rw', - ); -} "Adding read-write accessor does not use inline_slot_access"; - -lives_ok { __PACKAGE__->meta->make_immutable; } + lives_ok { + has lazy_attr => ( + is => 'ro', + isa => 'Bool', + lazy => 1, + default => sub {0}, + ); + } + "Adding lazy accessor does not use inline_slot_access"; + + lives_ok { + has rw_attr => ( + is => 'rw', + ); + } + "Adding read-write accessor does not use inline_slot_access"; + + lives_ok { __PACKAGE__->meta->make_immutable; } "Inling constructor does not use inline_slot_access"; +}