X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FAttribute.pm;h=959f71229704b839bb3f1cfb8e2645e29cc50388;hb=8fcbe7fb24ac710b860595ae1ecea066c3add1f5;hp=230efb5b8652f9fec63a48cdef7b90c39fb464e4;hpb=844fa04917ff42a952003c4302bcdd66a13621e0;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 230efb5..959f712 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -4,7 +4,8 @@ use strict; use warnings; use Carp 'confess'; -use Scalar::Util qw/blessed weaken/; +use Mouse::Util 'blessed'; +use Scalar::Util 'weaken'; sub new { my $class = shift; @@ -59,11 +60,7 @@ sub generate_accessor { my $type = $attribute->type_constraint; my $constraint = $attribute->find_type_constraint; my $builder = $attribute->builder; - - my $trigger = $attribute->trigger; - my $before = $trigger->{before}; - my $after = $trigger->{after}; - my $around = $trigger->{around}; + my $trigger = $attribute->trigger; my $accessor = 'sub { my $self = shift;'; @@ -72,36 +69,21 @@ sub generate_accessor { $accessor .= 'if (@_) { local $_ = $_[0];'; - if ($before) { - $accessor .= '$before->($self, $_, $attribute);'; - } - - if ($around) { - $accessor .= '$around->(sub { - my $self = shift; - $_ = $_[0]; - '; + if ($constraint) { + $accessor .= 'unless ($constraint->()) { + my $display = defined($_) ? overload::StrVal($_) : "undef"; + Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $display"); + }' } - if ($constraint) { - $accessor .= 'unless ($constraint->()) { - my $display = defined($_) ? overload::StrVal($_) : "undef"; - Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $display"); - }' - } + $accessor .= '$self->{$key} = $_;'; - $accessor .= '$self->{$key} = $_;'; - - if ($attribute->is_weak_ref) { - $accessor .= 'Scalar::Util::weaken($self->{$key}) if ref($self->{$key});'; - } - - if ($around) { - $accessor .= '}, $self, $_, $attribute);'; + if ($attribute->is_weak_ref) { + $accessor .= 'Scalar::Util::weaken($self->{$key}) if ref($self->{$key});'; } - if ($after) { - $accessor .= '$after->($self, $_, $attribute);'; + if ($trigger) { + $accessor .= '$trigger->($self, $_, $attribute);'; } $accessor .= '}'; @@ -272,17 +254,12 @@ sub validate_args { && $args->{isa} ne 'HashRef'; if ($args->{trigger}) { - if (ref($args->{trigger}) eq 'CODE') { - $args->{trigger} = { - after => $args->{trigger}, - }; - } - elsif (ref($args->{trigger}) eq 'HASH') { - Carp::carp "HASH-based form of trigger is deprecated. Please switch back to using the coderef form of trigger."; + if (ref($args->{trigger}) eq 'HASH') { + Carp::carp "HASH-based form of trigger has been removed. Only the coderef form of triggers are now supported."; } confess "Trigger must be a CODE ref on attribute ($name)" - if ref($args->{trigger}) ne 'HASH'; + if ref($args->{trigger}) ne 'CODE'; } return 1;