Skip to content
Browse files

allow for custom lifecycles by prepending '+'

  • Loading branch information...
1 parent bfe8e06 commit 0c395f899408b9b41548289e963e29231c4ca6db @jasonmay jasonmay committed May 12, 2011
Showing with 35 additions and 1 deletion.
  1. +6 −1 lib/Bread/Board/Service.pm
  2. +29 −0 t/031_custom_lifecycles.t
View
7 lib/Bread/Board/Service.pm
@@ -43,7 +43,12 @@ has 'lifecycle' => (
Class::MOP::class_of($base)->rebless_instance_back($self);
return if $lifecycle eq 'Null';
}
- Class::MOP::class_of("Bread::Board::LifeCycle::${lifecycle}")->apply($self);
+
+ my $lifecycle_role = $lifecycle =~ /^\+/
+ ? substr($lifecycle, 1)
+ : "Bread::Board::LifeCycle::${lifecycle}";
+ Class::MOP::load_class($lifecycle_role);
+ Class::MOP::class_of($lifecycle_role)->apply($self);
}
);
View
29 t/031_custom_lifecycles.t
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Moose;
+
+use Bread::Board::ConstructorInjection;
+
+{
+ package MyLifeCycle;
+ use Moose::Role;
+
+ with 'Bread::Board::LifeCycle::Singleton';
+}
+
+{
+ package MyClass;
+ use Moose;
+}
+
+my $s = Bread::Board::ConstructorInjection->new(
+ lifecycle => '+MyLifeCycle',
+ name => 'foo',
+ class => 'MyClass',
+);
+
+does_ok($s, 'MyLifeCycle');
+
+done_testing;

0 comments on commit 0c395f8

Please sign in to comment.
Something went wrong with that request. Please try again.