From 5067979bd1601d557362d79aa03a51665a761a39 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 21 Feb 2011 13:25:09 -0600 Subject: factor this out into a method --- lib/MooseX/Bread/Board/Role/Service.pm | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/MooseX/Bread/Board/Role/Service.pm b/lib/MooseX/Bread/Board/Role/Service.pm index 8442e3a..5e06eee 100644 --- a/lib/MooseX/Bread/Board/Role/Service.pm +++ b/lib/MooseX/Bread/Board/Role/Service.pm @@ -12,6 +12,18 @@ around get => sub { my $orig = shift; my $self = shift; + my $container = $self->parent_container; + + if ($self->associated_attribute->has_value($container)) { + return $self->associated_attribute->get_value($container); + } + + return $self->$orig(@_); +}; + +sub parent_container { + my $self = shift; + my $container = $self; until (!defined($container) || ($container->isa('Bread::Board::Container') @@ -20,12 +32,8 @@ around get => sub { } die "Couldn't find associated object!" unless defined $container; - if ($self->associated_attribute->has_value($container)) { - return $self->associated_attribute->get_value($container); - } - - return $self->$orig(@_); -}; + return $container; +} no Moose::Role; -- cgit v1.2.3-54-g00ecf