summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/Bread/Board/Role/Service.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-02-20 02:04:52 -0600
committerJesse Luehrs <doy@tozt.net>2011-02-20 02:04:52 -0600
commit8ad579f26a1c74d5685491df55b57e694e54e087 (patch)
treede3c03114a1932c1ddbb4a72ae5c34c5ceaf19f3 /lib/MooseX/Bread/Board/Role/Service.pm
parenta0cc11a5f9b60226a07054d6041cc45b4ea2221a (diff)
downloadbread-board-declare-8ad579f26a1c74d5685491df55b57e694e54e087.tar.gz
bread-board-declare-8ad579f26a1c74d5685491df55b57e694e54e087.zip
initial implementation
Diffstat (limited to 'lib/MooseX/Bread/Board/Role/Service.pm')
-rw-r--r--lib/MooseX/Bread/Board/Role/Service.pm32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/MooseX/Bread/Board/Role/Service.pm b/lib/MooseX/Bread/Board/Role/Service.pm
new file mode 100644
index 0000000..8442e3a
--- /dev/null
+++ b/lib/MooseX/Bread/Board/Role/Service.pm
@@ -0,0 +1,32 @@
+package MooseX::Bread::Board::Role::Service;
+use Moose::Role;
+
+has associated_attribute => (
+ is => 'ro',
+ isa => 'Class::MOP::Attribute',
+ required => 1,
+ weak_ref => 1,
+);
+
+around get => sub {
+ my $orig = shift;
+ my $self = shift;
+
+ my $container = $self;
+ until (!defined($container)
+ || ($container->isa('Bread::Board::Container')
+ && $container->does('MooseX::Bread::Board::Role::Object'))) {
+ $container = $container->parent;
+ }
+ 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(@_);
+};
+
+no Moose::Role;
+
+1;