From d1149a69c6121025816d388fadc3861e7407c594 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 21 Feb 2011 01:34:02 -0600 Subject: support the constructor_name option --- lib/MooseX/Bread/Board/Meta/Role/Attribute.pm | 9 ++++++++ t/33-constructor-name.t | 30 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 t/33-constructor-name.t diff --git a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm index c6c1335..e44b30e 100644 --- a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm +++ b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm @@ -40,6 +40,12 @@ has dependencies => ( predicate => 'has_dependencies', ); +has constructor_name => ( + is => 'ro', + isa => 'Str', + predicate => 'has_constructor_name', +); + after attach_to_class => sub { my $self = shift; @@ -55,6 +61,9 @@ after attach_to_class => sub { ($self->has_dependencies ? (dependencies => $self->dependencies) : ()), + ($self->has_constructor_name + ? (constructor_name => $self->constructor_name) + : ()), ); my $service; diff --git a/t/33-constructor-name.t b/t/33-constructor-name.t new file mode 100644 index 0000000..28647ee --- /dev/null +++ b/t/33-constructor-name.t @@ -0,0 +1,30 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + package Bar; + + sub create { bless {}, shift } +} + +{ + package Foo; + use Moose; + use MooseX::Bread::Board; + + has bar => ( + is => 'ro', + isa => 'Bar', + class => 'Bar', + constructor_name => 'create', + ); +} + +{ + my $foo = Foo->new; + isa_ok($foo->bar, 'Bar'); +} + +done_testing; -- cgit v1.2.3-54-g00ecf