use warnings;
use Carp 'confess';
-use Scalar::Util qw/blessed weaken/;
+use Mouse::Util qw/blessed weaken/;
sub new {
my $class = shift;
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;';
$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} = $_;';
-
- if ($attribute->is_weak_ref) {
- $accessor .= 'Scalar::Util::weaken($self->{$key}) if ref($self->{$key});';
- }
+ $accessor .= '$self->{$key} = $_;';
- if ($around) {
- $accessor .= '}, $self, $_, $attribute);';
+ if ($attribute->is_weak_ref) {
+ $accessor .= 'weaken($self->{$key}) if ref($self->{$key});';
}
- if ($after) {
- $accessor .= '$after->($self, $_, $attribute);';
+ if ($trigger) {
+ $accessor .= '$trigger->($self, $_, $attribute);';
}
$accessor .= '}';
&& $args->{isa} ne 'HashRef';
if ($args->{trigger}) {
- if (ref($args->{trigger}) eq 'CODE') {
- $args->{trigger} = {
- after => $args->{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 or HASH ref on attribute ($name)"
- if ref($args->{trigger}) ne 'HASH';
+ confess "Trigger must be a CODE ref on attribute ($name)"
+ if ref($args->{trigger}) ne 'CODE';
}
return 1;