package MooseX::Role::Parameterized;
-
use Moose (
extends => { -as => 'moose_extends' },
around => { -as => 'moose_around' },
qw/confess blessed/,
);
+moose_extends 'Moose::Exporter';
-use Carp 'croak';
use Moose::Role ();
-moose_extends 'Moose::Exporter';
use MooseX::Role::Parameterized::Meta::Role::Parameterizable;
sub parameter {
my $caller = shift;
+
+ confess "'parameter' may not be used inside of the role block"
+ if $CURRENT_METACLASS;
+
my $meta = Class::MOP::Class->initialize($caller);
my $names = shift;
my $code = pop @_;
for (@_) {
- croak "Roles do not currently support "
+ Carp::croak "Roles do not currently support "
. ref($_)
. " references for before method modifiers"
if ref $_;
my $code = pop @_;
for (@_) {
- croak "Roles do not currently support "
+ Carp::croak "Roles do not currently support "
. ref($_)
. " references for after method modifiers"
if ref $_;
my $code = pop @_;
for (@_) {
- croak "Roles do not currently support "
+ Carp::croak "Roles do not currently support "
. ref($_)
. " references for around method modifiers"
if ref $_;
my $caller = shift;
my $meta = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
- croak "Must specify at least one method" unless @_;
+ Carp::croak "Must specify at least one method" unless @_;
$meta->add_required_methods(@_);
}
my $caller = shift;
my $meta = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
- croak "Must specify at least one role" unless @_;
+ Carp::croak "Must specify at least one role" unless @_;
$meta->add_excluded_roles(@_);
}
$meta->add_override_method_modifier($name, $code);
}
-sub extends { croak "Roles do not currently support 'extends'" }
+sub extends { Carp::croak "Roles do not currently support 'extends'" }
-sub inner { croak "Roles cannot support 'inner'" }
+sub inner { Carp::croak "Roles cannot support 'inner'" }
-sub augment { croak "Roles cannot support 'augment'" }
+sub augment { Carp::croak "Roles cannot support 'augment'" }
1;
use MooseX::Role::Parameterized;
parameter name => (
- is => 'ro',
isa => 'Str',
required => 1,
);
C<role> block.
Parameters are declared using the L</parameter> keyword which very much
-resembles L<Moose/has>. You can use any option that L<Moose/has> accepts.
-These parameters will get their values when the consuming class (or role) uses
+resembles L<Moose/has>. You can use any option that L<Moose/has> accepts. The
+default value for the "is" option is "ro" as that's a very common case. These
+parameters will get their values when the consuming class (or role) uses
L<Moose/with>. A parameter object will be constructed with these values, and
passed to the C<role> block.
C<< method NAME => sub { ... }; >>. This is due to a limitation in Perl. In
return though you can use parameters I<in your methods>!
-You must use all the keywords in the role block. If it turns out to be correct,
-we'll compose the parameterizable role (everything outside the role block) with
-the parameterized role (everything inside the role block). We throw an error if
-you try to use a keyword outside of the role block, so don't worry about it for
-now.
-
L<Moose::Role/alias> and L<Moose::Role/excludes> are not yet supported. I'm
completely unsure of whether they should be handled by this module. Until we
figure out a plan, both declaring and providing a parameter named C<alias> or
Shawn M Moore, C<< <sartak@bestpractical.com> >>
+=head1 SEE ALSO
+
+L<MooseX::Role::Matcher>
+
=cut