X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse.pm;h=a170114960b4b8e2d0bbbc6ff5aae5a73eb49f78;hp=f8a775ad6b8578936550b5e858889fb177ea35fa;hb=b0b9f25a58185affc1f7a005929bf6b3f8770160;hpb=4f74e488e9d376f9def450da059e9a45d2870049 diff --git a/lib/Mouse.pm b/lib/Mouse.pm index f8a775a..a170114 100644 --- a/lib/Mouse.pm +++ b/lib/Mouse.pm @@ -3,7 +3,7 @@ use 5.006_002; use Mouse::Exporter; # enables strict and warnings -our $VERSION = '0.37_06'; +our $VERSION = '0.50'; use Carp qw(confess); use Scalar::Util qw(blessed); @@ -30,60 +30,60 @@ Mouse::Exporter->setup_import_methods( ], ); -# XXX: for backward compatibility -our @EXPORT = qw( - extends with - has - before after around - override super - augment inner - blessed confess -); -sub extends { Mouse::Meta::Class->initialize(scalar caller)->superclasses(@_) } +sub extends { + Mouse::Meta::Class->initialize(scalar caller)->superclasses(@_); + return; +} + +sub with { + Mouse::Util::apply_all_roles(scalar(caller), @_); + return; +} sub has { my $meta = Mouse::Meta::Class->initialize(scalar caller); my $name = shift; - $meta->throw_error(q{Usage: has 'name' => ( key => value, ... )}) + $meta->throw_error(q{Usage: has 'name' => ( key => value, ... )}) if @_ % 2; # odd number of arguments - $meta->add_attribute($_ => @_) for ref($name) ? @{$name} : $name; + if(ref $name){ # has [qw(foo bar)] => (...) + for (@{$name}){ + $meta->add_attribute($_ => @_); + } + } + else{ # has foo => (...) + $meta->add_attribute($name => @_); + } + return; } sub before { my $meta = Mouse::Meta::Class->initialize(scalar caller); - my $code = pop; - - for (@_) { - $meta->add_before_method_modifier($_ => $code); + for my $name($meta->_collect_methods(@_)) { + $meta->add_before_method_modifier($name => $code); } + return; } sub after { my $meta = Mouse::Meta::Class->initialize(scalar caller); - my $code = pop; - - for (@_) { - $meta->add_after_method_modifier($_ => $code); + for my $name($meta->_collect_methods(@_)) { + $meta->add_after_method_modifier($name => $code); } + return; } sub around { my $meta = Mouse::Meta::Class->initialize(scalar caller); - my $code = pop; - - for (@_) { - $meta->add_around_method_modifier($_ => $code); + for my $name($meta->_collect_methods(@_)) { + $meta->add_around_method_modifier($name => $code); } -} - -sub with { - Mouse::Util::apply_all_roles(scalar(caller), @_); + return; } our $SUPER_PACKAGE; @@ -122,6 +122,7 @@ sub inner { sub augment { #my($name, $method) = @_; Mouse::Meta::Class->initialize(scalar caller)->add_augment_method_modifier(@_); + return; } sub init_meta { @@ -150,7 +151,6 @@ sub init_meta { return $meta; } - 1; __END__ @@ -160,7 +160,7 @@ Mouse - Moose minus the antlers =head1 VERSION -This document describes Mouse version 0.37_06 +This document describes Mouse version 0.50 =head1 SYNOPSIS @@ -243,26 +243,17 @@ Returns this class' metaclass instance. Sets this class' superclasses. -=head2 C<< before (method|methods) => CodeRef >> - -Installs a "before" method modifier. See L or -L. - -Use of this feature requires L! - -=head2 C<< after (method|methods) => CodeRef >> +=head2 C<< before (method|methods|regexp) => CodeRef >> -Installs an "after" method modifier. See L or -L. +Installs a "before" method modifier. See L. -Use of this feature requires L! +=head2 C<< after (method|methods|regexp) => CodeRef >> -=head2 C<< around (method|methods) => CodeRef >> +Installs an "after" method modifier. See L. -Installs an "around" method modifier. See L or -L. +=head2 C<< around (method|methods|regexp) => CodeRef >> -Use of this feature requires L! +Installs an "around" method modifier. See L. =head2 C<< has (name|names) => parameters >> @@ -273,10 +264,16 @@ this class. Options: =item C<< is => ro|rw|bare >> -If specified, inlines a read-only/read-write accessor with the same name as +The I option accepts either I (for read/write), I (for read +only) or I (for nothing). These will create either a read/write accessor +or a read-only accessor respectively, using the same name as the C<$name> of the attribute. -=item C<< isa => TypeConstraint >> +If you need more control over how your accessors are named, you can +use the C, C and C options, however if you +use those, you won't need the I option. + +=item C<< isa => TypeName | ClassName >> Provides type checking in the constructor and accessor. The following types are supported. Any unknown type is taken to be a class check @@ -288,6 +285,17 @@ supported. Any unknown type is taken to be a class check For more documentation on type constraints, see L. +=item C<< does => RoleName >> + +This will accept the name of a role which the value stored in this attribute +is expected to have consumed. + +=item C<< coerce => Bool >> + +This will attempt to use coercion with the supplied type constraint to change +the value passed into any accessors or constructors. You B have supplied +a type constraint in order for this to work. See L +for an example. =item C<< required => Bool >> @@ -324,12 +332,12 @@ Lets you specify a method name for installing a clearer method, which clears the attribute's value from the instance. On the next read, lazy or builder will be invoked. -=item C<< handles => HashRef|ArrayRef >> +=item C<< handles => HashRef|ArrayRef|Regexp >> Lets you specify methods to delegate to the attribute. ArrayRef forwards the given method names to method calls on the attribute. HashRef maps local method names to remote method names called on the attribute. Other forms of -L, such as regular expression and coderef, are not yet supported. +L, such as RoleName and CodeRef, are not yet supported. =item C<< weak_ref => Bool >> @@ -388,11 +396,27 @@ You may use L to replace the superclass list. Please unimport Mouse (C) so that if someone calls one of the keywords (such as L) it will break loudly instead breaking subtly. +=head1 CAVEATS + +If you use Mouse::XS you might see a fatal error on callbacks +which include C, which typically occurs in such code +as C. This is not +a bug in Mouse. In fact, it is a bug in Perl (RT #69939). + +To work around this problem, surround C with C: + + sub callback { + # eval 'use NotInstalledModule'; # NG + eval{ eval 'use NotInstalledModule' }; # OK + } + +It seems ridiculous, but it works as you expected. + =head1 SOURCE CODE ACCESS We have a public git repository: - git clone git://jules.scsys.co.uk/gitmo/Mouse.git + git clone git://git.moose.perl.org/Mouse.git =head1 DEPENDENCIES @@ -404,13 +428,17 @@ L L +L + +L + L =head1 AUTHORS -Shawn M Moore, Esartak at gmail.comE +Shawn M Moore Esartak at gmail.comE -Yuval Kogman, Enothingmuch at woobling.orgE +Yuval Kogman Enothingmuch at woobling.orgE tokuhirom @@ -430,7 +458,7 @@ interface at L =head1 COPYRIGHT AND LICENSE -Copyright 2008-2009 Infinity Interactive, Inc. +Copyright (c) 2008-2010 Infinity Interactive, Inc. http://www.iinteractive.com/