X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse.pm;h=aac0782c667df4ff205aae814213c33330f58fa1;hp=047ab4e7c572f4b4a63bf478a42c3cfc28de6d7d;hb=cf59b7151d2b476a74b5abd84af37770ad4cf387;hpb=924c05c360ec9003649c5886fed23836bcafa8b4 diff --git a/lib/Mouse.pm b/lib/Mouse.pm index 047ab4e..aac0782 100644 --- a/lib/Mouse.pm +++ b/lib/Mouse.pm @@ -1,15 +1,12 @@ package Mouse; use 5.006_002; -use strict; -use warnings; +use Mouse::Exporter; # enables strict and warnings -our $VERSION = '0.37_02'; +our $VERSION = '0.40_09'; -use Exporter; - -use Carp 'confess'; -use Scalar::Util 'blessed'; +use Carp qw(confess); +use Scalar::Util qw(blessed); use Mouse::Util qw(load_class is_class_loaded get_code_package not_supported); @@ -20,29 +17,46 @@ use Mouse::Meta::Attribute; use Mouse::Object; use Mouse::Util::TypeConstraints (); -our @ISA = qw(Exporter); - -our @EXPORT = qw( - extends with - has - before after around - override super - augment inner - - blessed confess +Mouse::Exporter->setup_import_methods( + as_is => [qw( + extends with + has + before after around + override super + augment inner + ), + \&Scalar::Util::blessed, + \&Carp::confess, + ], ); -our %is_removable = map{ $_ => undef } @EXPORT; -delete $is_removable{blessed}; -delete $is_removable{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->add_attribute($_ => @_) for ref($name) ? @{$name} : $name; + $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($name => @_); + } + return; } sub before { @@ -53,6 +67,7 @@ sub before { for (@_) { $meta->add_before_method_modifier($_ => $code); } + return; } sub after { @@ -63,6 +78,7 @@ sub after { for (@_) { $meta->add_after_method_modifier($_ => $code); } + return; } sub around { @@ -73,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; @@ -115,6 +128,7 @@ sub inner { sub augment { #my($name, $method) = @_; Mouse::Meta::Class->initialize(scalar caller)->add_augment_method_modifier(@_); + return; } sub init_meta { @@ -123,16 +137,10 @@ sub init_meta { my $class = $args{for_class} or confess("Cannot call init_meta without specifying a for_class"); + my $base_class = $args{base_class} || 'Mouse::Object'; my $metaclass = $args{metaclass} || 'Mouse::Meta::Class'; - confess("The Metaclass $metaclass must be a subclass of Mouse::Meta::Class.") - unless $metaclass->isa('Mouse::Meta::Class'); - - # make a subtype for each Mouse class - Mouse::Util::TypeConstraints::class_type($class) - unless Mouse::Util::TypeConstraints::find_type_constraint($class); - my $meta = $metaclass->initialize($class); $meta->add_method(meta => sub{ @@ -142,74 +150,24 @@ sub init_meta { $meta->superclasses($base_class) unless $meta->superclasses; - return $meta; -} - -sub import { - my $class = shift; - - strict->import; - warnings->import; - - my $opts = do { - if (ref($_[0]) && ref($_[0]) eq 'HASH') { - shift @_; - } else { - +{ }; - } - }; - my $level = delete $opts->{into_level}; - $level = 0 unless defined $level; - my $caller = caller($level); - - # we should never export to main - if ($caller eq 'main') { - warn qq{$class does not export its sugar to the 'main' package.\n}; - return; - } - - $class->init_meta( - for_class => $caller, - ); - - if (@_) { - __PACKAGE__->export_to_level( $level+1, $class, @_); - } else { - # shortcut for the common case of no type character - no strict 'refs'; - for my $keyword (@EXPORT) { - *{ $caller . '::' . $keyword } = *{__PACKAGE__ . '::' . $keyword}; - } - } -} - -sub unimport { - my $caller = caller; - - my $stash = do{ - no strict 'refs'; - \%{$caller . '::'} - }; - - for my $keyword (@EXPORT) { - my $code; - if(exists $is_removable{$keyword} - && ($code = $caller->can($keyword)) - && get_code_package($code) eq __PACKAGE__){ + # make a class type for each Mouse class + Mouse::Util::TypeConstraints::class_type($class) + unless Mouse::Util::TypeConstraints::find_type_constraint($class); - delete $stash->{$keyword}; - } - } + return $meta; } 1; - __END__ =head1 NAME Mouse - Moose minus the antlers +=head1 VERSION + +This document describes Mouse version 0.40_09 + =head1 SYNOPSIS package Point; @@ -250,9 +208,8 @@ latter, if possible. Mouse aims to alleviate this by providing a subset of Moose's functionality, faster. -We're also going as light on dependencies as possible. -L or L is required -if you want support for L, L, and L. +We're also going as light on dependencies as possible. Mouse currently has +B except for testing modules. =head2 MOOSE COMPATIBILITY @@ -272,6 +229,8 @@ Moose, if you run into weird errors, it would be worth running: to see if the bug is caused by Mouse. Moose's diagnostics and validation are also much better. +See also L for compatibility and incompatibility with Moose. + =head2 MouseX Please don't copy MooseX code to MouseX. If you need extensions, you really @@ -292,25 +251,14 @@ 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! +Installs a "before" method modifier. See L. =head2 C<< after (method|methods) => CodeRef >> -Installs an "after" method modifier. See L or -L. - -Use of this feature requires L! - +Installs an "after" method modifier. See L. =head2 C<< around (method|methods) => CodeRef >> -Installs an "around" method modifier. See L or -L. - -Use of this feature requires L! - +Installs an "around" method modifier. See L. =head2 C<< has (name|names) => parameters >> Adds an attribute (or if passed an arrayref of names, multiple attributes) to @@ -439,7 +387,7 @@ keywords (such as L) it will break loudly instead breaking subtly. 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 @@ -447,15 +395,21 @@ Perl 5.6.2 or later. =head1 SEE ALSO +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