X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FUtil.pm;h=f1e2a24a57c4775eb03e42c415680dc1c137adb5;hb=60f0816092ffe11986388dd2bba56a356b697843;hp=0eec91d7b12d372b8dcc89f5161528616ddfb065;hpb=3eb89f709f04907580b508f821d6be2316fcb65f;p=gitmo%2FMoose.git diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index 0eec91d..f1e2a24 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -8,7 +8,7 @@ use Sub::Exporter; use Scalar::Util 'blessed'; use Class::MOP 0.60; -our $VERSION = '1.01'; +our $VERSION = '1.09'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -18,6 +18,7 @@ my @exports = qw[ search_class_by_role ensure_all_roles apply_all_roles + with_traits get_all_init_args get_all_attribute_values resolve_metatrait_alias @@ -105,7 +106,7 @@ sub _apply_all_roles { $meta = $role->[0]; } else { - Class::MOP::load_class( $role->[0] ); + Class::MOP::load_class( $role->[0] , $role->[1] ); $meta = Class::MOP::class_of( $role->[0] ); } @@ -136,6 +137,16 @@ sub _apply_all_roles { } } +sub with_traits { + my ($class, @roles) = @_; + return $class unless @roles; + return Moose::Meta::Class->create_anon_class( + superclasses => [$class], + roles => \@roles, + cache => 1, + )->name; +} + # instance deconstruction ... sub get_all_attribute_values { @@ -345,6 +356,11 @@ each of which can be followed by an optional hash reference of options This function is similar to L, but only applies roles that C<$applicant> does not already consume. +=item B + +This function creates a new class from C<$class_name> with each of +C<@role_names> applied. It returns the name of the new class. + =item B Returns a hash reference containing all of the C<$instance>'s @@ -373,12 +389,6 @@ when specifying the C or C option for an attribute: The name resolution mechanism is covered in L. -=item B - -Given a list of scalars, turns them into a proper list in English -("one and two", "one, two, three, and four"). This is used to help us -make nicer error messages. - =item B =item B @@ -387,6 +397,12 @@ Create an alias from the class C<$from> (or the current package, if C<$from> is unspecified), so that L works properly. +=item B + +Given a list of scalars, turns them into a proper list in English +("one and two", "one, two, three, and four"). This is used to help us +make nicer error messages. + =back =head1 TODO