From: Shawn M Moore Date: Sun, 9 Nov 2008 05:22:11 +0000 (+0000) Subject: Begin working on the rest of the sugar X-Git-Tag: 0.05~98 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a457ed601c5a9beb2fc0bd6ee9cc04e495b1d3ea;p=gitmo%2FMooseX-Role-Parameterized.git Begin working on the rest of the sugar --- diff --git a/lib/MooseX/Role/Parameterized.pm b/lib/MooseX/Role/Parameterized.pm index 3f23a53..f5403a8 100644 --- a/lib/MooseX/Role/Parameterized.pm +++ b/lib/MooseX/Role/Parameterized.pm @@ -1,15 +1,15 @@ #!/usr/bin/env perl package MooseX::Role::Parameterized; -use Moose; +use Moose qw/extends around confess/; use Moose::Role (); extends 'Moose::Exporter'; use MooseX::Role::Parameterized::Meta::Role; -our $CURRENT_ROLE; +our $CURRENT_METACLASS; __PACKAGE__->setup_import_methods( - with_caller => ['parameter', 'role'], + with_caller => ['parameter', 'role', 'has'], ); sub parameter { @@ -49,5 +49,19 @@ around _make_wrapper => sub { return $orig->(@_); }; +sub has { + confess "has must be called within the role { ... } block." + unless $CURRENT_METACLASS; + + my $caller = shift; + my $names = shift; + + $names = [$names] if !ref($names); + + for my $name (@$names) { + $CURRENT_METACLASS->add_attribute($name, @_); + } +} + 1;