Skip to content

Commit

Permalink
Remove hardcoded 'child' attribute name. D'oh! Thanks again, Sartak.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaputo committed Aug 23, 2009
1 parent 566af4b commit caa59ae
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ObserverTrait.pm
@@ -1,9 +1,18 @@
package ObserverTrait;
use Moose::Role;
use Scalar::Util qw(weaken);

has trigger => (
is => 'ro',
default => sub {
my $meta_self = shift;

# $meta_self->name() is not set yet.
# Weaken $meta_self so that the closure isn't fatal.
# TODO - If we can get the name out here, then we save a name()
# method call every trigger.
weaken $meta_self;

sub {
my ($self, $value) = @_;

Expand All @@ -12,9 +21,10 @@ has trigger => (
# destructing on clear, which also triggers ignore().

return unless defined $value;

$self->observe_role(
observed => $value,
role => $self->meta->get_attribute('child')->role(),
role => $self->meta->get_attribute($meta_self->name())->role(),
);
}
}
Expand Down

0 comments on commit caa59ae

Please sign in to comment.