From: gfx Date: Thu, 3 Dec 2009 03:44:32 +0000 (+0900) Subject: Clean the code up X-Git-Tag: 0.40_09~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9ee0e57c8c1ca23a9de421bf3ecf9e73ba795898;p=gitmo%2FMouse.git Clean the code up --- diff --git a/lib/Mouse.pm b/lib/Mouse.pm index 334e8d3..4449900 100644 --- a/lib/Mouse.pm +++ b/lib/Mouse.pm @@ -30,26 +30,33 @@ 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($_ => @_); + } + return; } sub before { @@ -60,6 +67,7 @@ sub before { for (@_) { $meta->add_before_method_modifier($_ => $code); } + return; } sub after { @@ -70,6 +78,7 @@ sub after { for (@_) { $meta->add_after_method_modifier($_ => $code); } + return; } sub around { @@ -80,10 +89,7 @@ sub around { for (@_) { $meta->add_around_method_modifier($_ => $code); } -} - -sub with { - Mouse::Util::apply_all_roles(scalar(caller), @_); + return; } our $SUPER_PACKAGE; @@ -122,6 +128,7 @@ sub inner { sub augment { #my($name, $method) = @_; Mouse::Meta::Class->initialize(scalar caller)->add_augment_method_modifier(@_); + return; } sub init_meta { diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index 9d9a98f..56b90b7 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -25,18 +25,34 @@ Mouse::Exporter->setup_import_methods( ], ); -# XXX: for backward compatibility -our @EXPORT = qw( - extends with - has - before after around - override super - augment inner - requires excludes +sub extends { + Carp::croak "Roles do not support 'extends'"; +} - blessed confess -); +sub with { + my $meta = Mouse::Meta::Role->initialize(scalar caller); + Mouse::Util::apply_all_roles($meta->name, @_); + return; +} + +sub has { + my $meta = Mouse::Meta::Role->initialize(scalar caller); + my $name = shift; + + $meta->throw_error(q{Usage: has 'name' => ( key => value, ... )}) + if @_ % 2; # odd number of arguments + + if(ref $name){ # has [qw(foo bar)] => (...) + for (@{$name}){ + $meta->add_attribute($_ => @_); + } + } + else{ # has foo => (...) + $meta->add_attribute($_ => @_); + } + return; +} sub before { my $meta = Mouse::Meta::Role->initialize(scalar caller); @@ -45,6 +61,7 @@ sub before { for (@_) { $meta->add_before_method_modifier($_ => $code); } + return; } sub after { @@ -54,6 +71,7 @@ sub after { for (@_) { $meta->add_after_method_modifier($_ => $code); } + return; } sub around { @@ -63,6 +81,7 @@ sub around { for (@_) { $meta->add_around_method_modifier($_ => $code); } + return; } @@ -74,6 +93,7 @@ sub super { sub override { # my($name, $code) = @_; Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_); + return; } # We keep the same errors messages as Moose::Role emits, here. @@ -85,26 +105,11 @@ sub augment { Carp::croak "Roles cannot support 'augment'"; } -sub has { - my $meta = Mouse::Meta::Role->initialize(scalar caller); - my $name = shift; - - $meta->add_attribute($_ => @_) for ref($name) ? @{$name} : $name; -} - -sub extends { - Carp::croak "Roles do not support 'extends'" -} - -sub with { - my $meta = Mouse::Meta::Role->initialize(scalar caller); - Mouse::Util::apply_all_roles($meta->name, @_); -} - sub requires { my $meta = Mouse::Meta::Role->initialize(scalar caller); $meta->throw_error("Must specify at least one method") unless @_; $meta->add_required_methods(@_); + return; } sub excludes {