X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose.pm;h=6c48b606dd00d51ffc61d01292341ce838903e55;hb=fd542f49cbac7f7834f454ee9b4ec9a15fe5d13b;hp=39788c1e5a0a2458d52c84ded094b35f7a464d4c;hpb=32dd4a951fc7ad9da42ec8072af052d22cb06dd5;p=gitmo%2FMoose.git diff --git a/lib/Moose.pm b/lib/Moose.pm index 39788c1..6c48b60 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -4,7 +4,7 @@ package Moose; use strict; use warnings; -our $VERSION = '0.34'; +our $VERSION = '0.39'; our $AUTHORITY = 'cpan:STEVAN'; use Scalar::Util 'blessed', 'reftype'; @@ -13,10 +13,11 @@ use Sub::Name 'subname'; use Sub::Exporter; -use Class::MOP 0.49; +use Class::MOP 0.51; use Moose::Meta::Class; use Moose::Meta::TypeConstraint; +use Moose::Meta::TypeConstraint::Class; use Moose::Meta::TypeCoercion; use Moose::Meta::Attribute; use Moose::Meta::Instance; @@ -25,23 +26,23 @@ use Moose::Meta::Role; use Moose::Object; use Moose::Util::TypeConstraints; +use Moose::Util (); { my $CALLER; sub init_meta { my ( $class, $base_class, $metaclass ) = @_; - $base_class = $class unless defined $base_class; - $metaclass = 'Moose::Meta::Class' unless defined $metaclass; + $base_class = 'Moose::Object' unless defined $base_class; + $metaclass = 'Moose::Meta::Class' unless defined $metaclass; confess "The Metaclass $metaclass must be a subclass of Moose::Meta::Class." unless $metaclass->isa('Moose::Meta::Class'); # make a subtype for each Moose class - subtype $class => as 'Object' => where { $_->isa($class) } => - optimize_as { blessed( $_[0] ) && $_[0]->isa($class) } - unless find_type_constraint($class); + class_type($class) + unless find_type_constraint($class); my $meta; if ( $class->can('meta') ) { @@ -63,7 +64,6 @@ use Moose::Util::TypeConstraints; $meta = $metaclass->initialize($class); $meta->add_method( 'meta' => sub { - # re-initialize so it inherits properly $metaclass->initialize( blessed( $_[0] ) || $_[0] ); } @@ -73,6 +73,8 @@ use Moose::Util::TypeConstraints; # make sure they inherit from Moose::Object $meta->superclasses($base_class) unless $meta->superclasses(); + + return $meta; } my %exports = ( @@ -92,18 +94,17 @@ use Moose::Util::TypeConstraints; with => sub { my $class = $CALLER; return subname 'Moose::with' => sub (@) { - my (@roles) = @_; - confess "Must specify at least one role" unless @roles; - Class::MOP::load_class($_) for @roles; - $class->meta->_apply_all_roles(@roles); + Moose::Util::apply_all_roles($class->meta, @_) }; }, has => sub { my $class = $CALLER; return subname 'Moose::has' => sub ($;%) { - my ( $name, %options ) = @_; + my $name = shift; + die 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1; + my %options = @_; my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; - $class->meta->_process_attribute( $_, %options ) for @$attrs; + $class->meta->add_attribute( $_, %options ) for @$attrs; }; }, before => sub { @@ -160,6 +161,12 @@ use Moose::Util::TypeConstraints; $class->meta->add_augment_method_modifier( $name => $method ); }; }, + make_immutable => sub { + my $class = $CALLER; + return subname 'Moose::make_immutable' => sub { + $class->meta->make_immutable(@_); + }; + }, confess => sub { return \&Carp::confess; }, @@ -189,6 +196,11 @@ use Moose::Util::TypeConstraints; sub import { $CALLER = _get_caller(@_); + # this works because both pragmas set $^H (see perldoc perlvar) + # which affects the current compilation - i.e. the file who use'd + # us - which is why we don't need to do anything special to make + # it affect that file rather than this one (which is already compiled) + strict->import; warnings->import; @@ -259,7 +271,7 @@ __END__ =head1 NAME -Moose - A complete modern object system for Perl 5 +Moose - A postmodern object system for Perl 5 =head1 SYNOPSIS @@ -315,7 +327,7 @@ Yes, I believe that it is. Moose has been used successfully in production environemnts by several people and companies (including the one I work for). There are Moose applications -which have been in production with little or no issue now for over a year. +which have been in production with little or no issue now for well over a year. I consider it highly stable and we are commited to keeping it stable. Of course, in the end, you need to make this call yourself. If you have @@ -329,6 +341,19 @@ Instead, it is an OO system for Perl 5. I built Moose because I was tired of writing the same old boring Perl 5 OO code, and drooling over Perl 6 OO. So instead of switching to Ruby, I wrote Moose :) +=head2 Wait, I modern, I thought it was just I? + +So I was reading Larry Wall's talk from the 1999 Linux World entitled +"Perl, the first postmodern computer language" in which he talks about how +he picked the features for Perl because he thought they were cool and he +threw out the ones that he thought sucked. This got me thinking about how +we have done the same thing in Moose. For Moose, we have "borrowed" features +from Perl 6, CLOS (LISP), Smalltalk, Java, BETA, OCaml, Ruby and more, and +the bits we didn't like (cause they sucked) we tossed aside. So for this +reason (and a few others) I have re-dubbed Moose a I object system. + +Nuff Said. + =head2 Moose Extensions The L namespace is the official place to find Moose extensions. @@ -529,7 +554,7 @@ quick example (soon to be expanded into a Moose::Cookbook::Recipe): has 'parent' => ( is => 'rw', isa => 'Tree', - is_weak_ref => 1, + weak_ref => 1, handles => { parent_node => 'node', siblings => 'children', @@ -878,7 +903,7 @@ Shawn (sartak) Moore =head1 COPYRIGHT AND LICENSE -Copyright 2006, 2007 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L