Add make_immutable to the SYNOPSIS
[gitmo/Mouse.git] / lib / Mouse.pm
index 10998df..22827e5 100644 (file)
@@ -3,9 +3,9 @@ use 5.006_002;
 
 use Mouse::Exporter; # enables strict and warnings
 
-our $VERSION = '0.37_05';
+our $VERSION = '0.50_01';
 
-use Carp qw(confess);
+use Carp         qw(confess);
 use Scalar::Util qw(blessed);
 
 use Mouse::Util qw(load_class is_class_loaded get_code_package not_supported);
@@ -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, ... )})\r
+    $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 {
@@ -130,13 +131,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';
 
-    # 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{
@@ -146,10 +144,13 @@ sub init_meta {
     $meta->superclasses($base_class)
         unless $meta->superclasses;
 
+    # make a class type for each Mouse class
+    Mouse::Util::TypeConstraints::class_type($class)
+        unless Mouse::Util::TypeConstraints::find_type_constraint($class);
+
     return $meta;
 }
 
-
 1;
 __END__
 
@@ -159,7 +160,7 @@ Mouse - Moose minus the antlers
 
 =head1 VERSION
 
-This document describes Mouse version 0.37_05
+This document describes Mouse version 0.50_01
 
 =head1 SYNOPSIS
 
@@ -175,6 +176,9 @@ This document describes Mouse version 0.37_05
         $self->y(0);
     }
 
+
+    __PACKAGE__->meta->make_immutable();
+
     package Point3D;
     use Mouse;
 
@@ -187,6 +191,8 @@ This document describes Mouse version 0.37_05
         $self->z(0);
     };
 
+    __PACKAGE__->meta->make_immutable();
+
 =head1 DESCRIPTION
 
 L<Moose> is wonderful. B<Use Moose instead of Mouse.>
@@ -201,9 +207,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<Class::Method::Modifiers::Fast> or L<Class::Method::Modifiers> is required
-if you want support for L</before>, L</after>, and L</around>.
+We're also going as light on dependencies as possible. Mouse currently has
+B<no dependencies> except for testing modules.
 
 =head2 MOOSE COMPATIBILITY
 
@@ -223,6 +228,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<Mouse::Spec> for compatibility and incompatibility with Moose.
+
 =head2 MouseX
 
 Please don't copy MooseX code to MouseX. If you need extensions, you really
@@ -241,26 +248,17 @@ Returns this class' metaclass instance.
 
 Sets this class' superclasses.
 
-=head2 C<< before (method|methods) => CodeRef >>
-
-Installs a "before" method modifier. See L<Moose/before> or
-L<Class::Method::Modifiers/before>.
-
-Use of this feature requires L<Class::Method::Modifiers>!
+=head2 C<< before (method|methods|regexp) => CodeRef >>
 
-=head2 C<< after (method|methods) => CodeRef >>
+Installs a "before" method modifier. See L<Moose/before>.
 
-Installs an "after" method modifier. See L<Moose/after> or
-L<Class::Method::Modifiers/after>.
+=head2 C<< after (method|methods|regexp) => CodeRef >>
 
-Use of this feature requires L<Class::Method::Modifiers>!
+Installs an "after" method modifier. See L<Moose/after>.
 
-=head2 C<< around (method|methods) => CodeRef >>
+=head2 C<< around (method|methods|regexp) => CodeRef >>
 
-Installs an "around" method modifier. See L<Moose/around> or
-L<Class::Method::Modifiers/around>.
-
-Use of this feature requires L<Class::Method::Modifiers>!
+Installs an "around" method modifier. See L<Moose/around>.
 
 =head2 C<< has (name|names) => parameters >>
 
@@ -271,10 +269,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<is> option accepts either I<rw> (for read/write), I<ro> (for read
+only) or I<bare> (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<reader>, C<writer> and C<accessor> options, however if you
+use those, you won't need the I<is> 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
@@ -286,6 +290,17 @@ supported. Any unknown type is taken to be a class check
 
 For more documentation on type constraints, see L<Mouse::Util::TypeConstraints>.
 
+=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<must> have supplied
+a type constraint in order for this to work. See L<Moose::Cookbook::Basics::Recipe5>
+for an example.
 
 =item C<< required => Bool >>
 
@@ -322,12 +337,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</handles>, such as regular expression and coderef, are not yet supported.
+L</handles>, such as RoleName and CodeRef, are not yet supported.
 
 =item C<< weak_ref => Bool >>
 
@@ -386,11 +401,27 @@ You may use L</extends> to replace the superclass list.
 Please unimport Mouse (C<no Mouse>) so that if someone calls one of the
 keywords (such as L</extends>) 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<eval 'BEGIN{ die }'>, which typically occurs in such code
+as C<eval 'use NotInstalledModule'>. This is not
+a bug in Mouse. In fact, it is a bug in Perl (RT #69939).
+
+To work around this problem, surround C<eval STRING> with C<eval BLOCK>:
+
+    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
 
@@ -398,15 +429,21 @@ Perl 5.6.2 or later.
 
 =head1 SEE ALSO
 
+L<Mouse::Spec>
+
 L<Moose>
 
+L<Moose::Manual>
+
+L<Moose::Cookbook>
+
 L<Class::MOP>
 
 =head1 AUTHORS
 
-Shawn M Moore, E<lt>sartak at gmail.comE<gt>
+Shawn M Moore E<lt>sartak at gmail.comE<gt>
 
-Yuval Kogman, E<lt>nothingmuch at woobling.orgE<gt>
+Yuval Kogman E<lt>nothingmuch at woobling.orgE<gt>
 
 tokuhirom
 
@@ -426,7 +463,7 @@ interface at L<http://rt.cpan.org/Public/Dist/Display.html?Name=Mouse>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2008-2009 Infinity Interactive, Inc.
+Copyright (c) 2008-2010 Infinity Interactive, Inc.
 
 http://www.iinteractive.com/