From: Hans Dieter Pearcey Date: Fri, 26 Jun 2009 01:20:23 +0000 (-0700) Subject: eradicate metaclasses X-Git-Tag: 0.89_02~115 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c13596ce8b488f81cf0e2a7624b9bbc612aa0346;p=gitmo%2FMoose.git eradicate metaclasses --- diff --git a/lib/Moose/AttributeHelpers.pm b/lib/Moose/AttributeHelpers.pm index 7bb7cf9..8b05ce7 100644 --- a/lib/Moose/AttributeHelpers.pm +++ b/lib/Moose/AttributeHelpers.pm @@ -17,16 +17,6 @@ use Moose::AttributeHelpers::Trait::Collection::Hash; use Moose::AttributeHelpers::Trait::Collection::ImmutableHash; use Moose::AttributeHelpers::Trait::Collection::Bag; -use Moose::AttributeHelpers::Counter; -use Moose::AttributeHelpers::Number; -use Moose::AttributeHelpers::String; -use Moose::AttributeHelpers::Bool; -use Moose::AttributeHelpers::Collection::List; -use Moose::AttributeHelpers::Collection::Array; -use Moose::AttributeHelpers::Collection::Hash; -use Moose::AttributeHelpers::Collection::ImmutableHash; -use Moose::AttributeHelpers::Collection::Bag; - 1; __END__ @@ -44,7 +34,7 @@ Moose::AttributeHelpers - Extend your attribute interfaces use Moose::AttributeHelpers; has 'mapping' => ( - metaclass => 'Collection::Hash', + traits => [ 'Collection::Hash' ], is => 'rw', isa => 'HashRef[Str]', default => sub { {} }, diff --git a/lib/Moose/AttributeHelpers/Bool.pm b/lib/Moose/AttributeHelpers/Bool.pm deleted file mode 100644 index cb64545..0000000 --- a/lib/Moose/AttributeHelpers/Bool.pm +++ /dev/null @@ -1,70 +0,0 @@ -package Moose::AttributeHelpers::Bool; -use Moose; - -our $VERSION = '0.83'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -extends 'Moose::Meta::Attribute'; -with 'Moose::AttributeHelpers::Trait::Bool'; - -no Moose; - -# register the alias ... -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Bool; -sub register_implementation { 'Moose::AttributeHelpers::Bool' } - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::AttributeHelpers::Bool - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=item B - -=item B - -Run before its superclass method. - -=item B - -Run after its superclass method. - -=back - -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut - diff --git a/lib/Moose/AttributeHelpers/Collection/Array.pm b/lib/Moose/AttributeHelpers/Collection/Array.pm deleted file mode 100644 index b700348..0000000 --- a/lib/Moose/AttributeHelpers/Collection/Array.pm +++ /dev/null @@ -1,86 +0,0 @@ - -package Moose::AttributeHelpers::Collection::Array; -use Moose; - -our $VERSION = '0.83'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -extends 'Moose::Meta::Attribute'; -with 'Moose::AttributeHelpers::Trait::Collection::Array'; - -no Moose; - -# register the alias ... -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Collection::Array; -sub register_implementation { 'Moose::AttributeHelpers::Collection::Array' } - - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::AttributeHelpers::Collection::Array - -=head1 SYNOPSIS - - package Stuff; - use Moose; - use Moose::AttributeHelpers; - - has 'options' => ( - metaclass => 'Collection::Array', - is => 'ro', - isa => 'ArrayRef[Int]', - default => sub { [] }, - handles => { - add_options => 'push', - remove_last_option => 'pop', - } - ); - -=head1 DESCRIPTION - -This module provides an Array attribute which provides a number of -array operations. See L -for more details. - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=item B - -=back - -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/AttributeHelpers/Collection/Bag.pm b/lib/Moose/AttributeHelpers/Collection/Bag.pm deleted file mode 100644 index f510260..0000000 --- a/lib/Moose/AttributeHelpers/Collection/Bag.pm +++ /dev/null @@ -1,89 +0,0 @@ - -package Moose::AttributeHelpers::Collection::Bag; -use Moose; - -our $VERSION = '0.83'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -extends 'Moose::Meta::Attribute'; -with 'Moose::AttributeHelpers::Trait::Collection::Bag'; - -no Moose; - -# register the alias ... -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Collection::Bag; -sub register_implementation { 'Moose::AttributeHelpers::Collection::Bag' } - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::AttributeHelpers::Collection::Bag - -=head1 SYNOPSIS - - package Stuff; - use Moose; - use Moose::AttributeHelpers; - - has 'word_histogram' => ( - metaclass => 'Collection::Bag', - is => 'ro', - isa => 'Bag', # optional ... as is defalt - handles => { - add_word => 'add', - get_count_for => 'get', - has_any_words => 'empty', - num_words => 'count', - delete_word => 'delete', - } - ); - -=head1 DESCRIPTION - -This module provides a Bag attribute which provides a number of -bag-like operations. See L -for more details. - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=item B - -=item B - -=back - -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/AttributeHelpers/Collection/Hash.pm b/lib/Moose/AttributeHelpers/Collection/Hash.pm deleted file mode 100644 index cf707bc..0000000 --- a/lib/Moose/AttributeHelpers/Collection/Hash.pm +++ /dev/null @@ -1,89 +0,0 @@ - -package Moose::AttributeHelpers::Collection::Hash; -use Moose; - -our $VERSION = '0.83'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -extends 'Moose::Meta::Attribute'; -with 'Moose::AttributeHelpers::Trait::Collection::Hash'; - -no Moose; - -# register the alias ... -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Collection::Hash; -sub register_implementation { 'Moose::AttributeHelpers::Collection::Hash' } - - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::AttributeHelpers::Collection::Hash - -=head1 SYNOPSIS - - package Stuff; - use Moose; - use Moose::AttributeHelpers; - - has 'options' => ( - metaclass => 'Collection::Hash', - is => 'ro', - isa => 'HashRef[Str]', - default => sub { {} }, - handles => { - set_option => 'set', - get_option => 'get', - has_options => 'empty', - num_options => 'count', - delete_option => 'delete', - } - ); - -=head1 DESCRIPTION - -This module provides a Hash attribute which provides a number of -hash-like operations. See L -for more details. - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=item B - -=back - -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/AttributeHelpers/Collection/ImmutableHash.pm b/lib/Moose/AttributeHelpers/Collection/ImmutableHash.pm deleted file mode 100644 index 56a7532..0000000 --- a/lib/Moose/AttributeHelpers/Collection/ImmutableHash.pm +++ /dev/null @@ -1,87 +0,0 @@ - -package Moose::AttributeHelpers::Collection::ImmutableHash; -use Moose; - -our $VERSION = '0.83'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -extends 'Moose::Meta::Attribute'; -with 'Moose::AttributeHelpers::Trait::Collection::ImmutableHash'; - -no Moose; - -# register the alias ... -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Collection::ImmutableHash; -sub register_implementation { 'Moose::AttributeHelpers::Collection::ImmutableHash' } - - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::AttributeHelpers::Collection::ImmutableHash - -=head1 SYNOPSIS - - package Stuff; - use Moose; - use Moose::AttributeHelpers; - - has 'options' => ( - metaclass => 'Collection::ImmutableHash', - is => 'ro', - isa => 'HashRef[Str]', - default => sub { {} }, - handles => { - get_option => 'get', - has_options => 'empty', - get_option_list => 'keys', - } - ); - -=head1 DESCRIPTION - -This module provides a immutable HashRef attribute which provides a number of -hash-line operations. See L -for more details. - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=item B - -=back - -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/AttributeHelpers/Collection/List.pm b/lib/Moose/AttributeHelpers/Collection/List.pm deleted file mode 100644 index 53b3ca6..0000000 --- a/lib/Moose/AttributeHelpers/Collection/List.pm +++ /dev/null @@ -1,86 +0,0 @@ - -package Moose::AttributeHelpers::Collection::List; -use Moose; - -our $VERSION = '0.83'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -extends 'Moose::Meta::Attribute'; -with 'Moose::AttributeHelpers::Trait::Collection::List'; - -no Moose; - -# register the alias ... -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Collection::List; -sub register_implementation { 'Moose::AttributeHelpers::Collection::List' } - - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::AttributeHelpers::Collection::List - -=head1 SYNOPSIS - - package Stuff; - use Moose; - use Moose::AttributeHelpers; - - has 'options' => ( - metaclass => 'Collection::List', - is => 'ro', - isa => 'ArrayRef[Int]', - default => sub { [] }, - handles => { - map_options => 'map', - filter_options => 'grep', - } - ); - -=head1 DESCRIPTION - -This module provides an List attribute which provides a number of -list operations. See L -for more details. - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=item B - -=back - -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/AttributeHelpers/Counter.pm b/lib/Moose/AttributeHelpers/Counter.pm deleted file mode 100644 index 3c7c156..0000000 --- a/lib/Moose/AttributeHelpers/Counter.pm +++ /dev/null @@ -1,71 +0,0 @@ - -package Moose::AttributeHelpers::Counter; -use Moose; - -our $VERSION = '0.83'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -extends 'Moose::Meta::Attribute'; -with 'Moose::AttributeHelpers::Trait::Counter'; - -no Moose; - -# register the alias ... -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Counter; -sub register_implementation { 'Moose::AttributeHelpers::Counter' } - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::AttributeHelpers::Counter - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=item B - -=item B - -Run before its superclass method. - -=item B - -Run after its superclass method. - -=back - -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut - diff --git a/lib/Moose/AttributeHelpers/Number.pm b/lib/Moose/AttributeHelpers/Number.pm deleted file mode 100644 index 0205760..0000000 --- a/lib/Moose/AttributeHelpers/Number.pm +++ /dev/null @@ -1,125 +0,0 @@ -package Moose::AttributeHelpers::Number; -use Moose; - -our $VERSION = '0.83'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -extends 'Moose::Meta::Attribute'; -with 'Moose::AttributeHelpers::Trait::Number'; - -no Moose; - -# register the alias ... -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::Number; -sub register_implementation { 'Moose::AttributeHelpers::Number' } - -1; - -=pod - -=head1 NAME - -Moose::AttributeHelpers::Number - -=head1 SYNOPSIS - - package Real; - use Moose; - use Moose::AttributeHelpers; - - has 'integer' => ( - metaclass => 'Number', - is => 'ro', - isa => 'Int', - default => sub { 5 }, - handles => { - set => 'set', - add => 'add', - sub => 'sub', - mul => 'mul', - div => 'div', - mod => 'mod', - abs => 'abs', - } - ); - - my $real = Real->new(); - $real->add(5); # same as $real->integer($real->integer + 5); - $real->sub(2); # same as $real->integer($real->integer - 2); - -=head1 DESCRIPTION - -This provides a simple numeric attribute, which supports most of the -basic math operations. - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=back - -=head1 PROVIDED METHODS - -It is important to note that all those methods do in place -modification of the value stored in the attribute. - -=over 4 - -=item I - -Alternate way to set the value. - -=item I - -Adds the current value of the attribute to C<$value>. - -=item I - -Subtracts the current value of the attribute to C<$value>. - -=item I - -Multiplies the current value of the attribute to C<$value>. - -=item I
- -Divides the current value of the attribute to C<$value>. - -=item I - -Modulus the current value of the attribute to C<$value>. - -=item I - -Sets the current value of the attribute to its absolute value. - -=back - -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Robert Boone - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/AttributeHelpers/String.pm b/lib/Moose/AttributeHelpers/String.pm deleted file mode 100644 index f36a20a..0000000 --- a/lib/Moose/AttributeHelpers/String.pm +++ /dev/null @@ -1,151 +0,0 @@ - -package Moose::AttributeHelpers::String; -use Moose; - -our $VERSION = '0.83'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - -extends 'Moose::Meta::Attribute'; -with 'Moose::AttributeHelpers::Trait::String'; - -no Moose; - -# register the alias ... -package # hide me from search.cpan.org - Moose::Meta::Attribute::Custom::String; -sub register_implementation { 'Moose::AttributeHelpers::String' } - -1; - -__END__ - -=pod - -=head1 NAME - -Moose::AttributeHelpers::String - -=head1 SYNOPSIS - - package MyHomePage; - use Moose; - use Moose::AttributeHelpers; - - has 'text' => ( - metaclass => 'String', - is => 'rw', - isa => 'Str', - default => sub { '' }, - handles => { - "add_text" => "append", - "replace_text" => "replace", - } - ); - - my $page = MyHomePage->new(); - $page->add_text("foo"); # same as $page->text($page->text . "foo"); - -=head1 DESCRIPTION - -This module provides a simple string attribute, to which mutating string -operations can be applied more easily (no need to make an lvalue attribute -metaclass or use temporary variables). Additional methods are provided for -completion. - -If your attribute definition does not include any of I, I, I -or I but does use the C metaclass, then this module applies -defaults as in the L above. This allows for a very basic counter -definition: - - has 'foo' => (metaclass => 'String'); - $obj->append_foo; - -=head1 METHODS - -=over 4 - -=item B - -=item B - -=item B - -=item B - -=item B - -Run before its superclass method. - -=item B - -Run after its superclass method. - -=back - -=head1 PROVIDED METHODS - -It is important to note that all those methods do in place -modification of the value stored in the attribute. - -=over 4 - -=item I - -Increments the value stored in this slot using the magical string autoincrement -operator. Note that Perl doesn't provide analogous behavior in C<-->, so -C is not available. - -=item I C<$string> - -Append a string, like C<.=>. - -=item I C<$string> - -Prepend a string. - -=item I C<$pattern> C<$replacement> - -Performs a regexp substitution (L). There is no way to provide the -C flag, but code references will be accepted for the replacement, causing -the regex to be modified with a single C. C can be applied using the -C operator. - -=item I C<$pattern> - -Like I but without the replacement. Provided mostly for completeness. - -=item C - -L - -=item C - -L - -=item C - -Sets the string to the empty string (not the value passed to C). - -=back - -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2007-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/t/070_attribute_helpers/010_array_from_role.t b/t/070_attribute_helpers/010_array_from_role.t index 667ad16..b72ec51 100644 --- a/t/070_attribute_helpers/010_array_from_role.t +++ b/t/070_attribute_helpers/010_array_from_role.t @@ -20,7 +20,7 @@ BEGIN { use Moose::Role; has 'options' => ( - metaclass => 'Collection::Array', + traits => [ 'Collection::Array' ], is => 'ro', isa => 'ArrayRef[Foo]', ); @@ -29,11 +29,11 @@ BEGIN { use Moose::Role; has 'stuff' => ( - metaclass => 'Collection::Array', + traits => [ 'Collection::Array' ], is => 'ro', isa => 'ArrayRef', - provides => { - 'get' => 'get_stuff' + handles => { + get_stuff => 'get', } ); diff --git a/t/070_attribute_helpers/011_counter_with_defaults.t b/t/070_attribute_helpers/011_counter_with_defaults.t index 385f41c..09fc69a 100644 --- a/t/070_attribute_helpers/011_counter_with_defaults.t +++ b/t/070_attribute_helpers/011_counter_with_defaults.t @@ -54,5 +54,5 @@ is_deeply($counter->handles, { 'dec_counter' => 'dec', 'reset_counter' => 'reset', 'set_counter' => 'set', -}, '... got the right default provides methods'); +}, '... got the right default handles methods'); diff --git a/t/070_attribute_helpers/020_remove_attribute.t b/t/070_attribute_helpers/020_remove_attribute.t index 3a96e7a..08f4662 100644 --- a/t/070_attribute_helpers/020_remove_attribute.t +++ b/t/070_attribute_helpers/020_remove_attribute.t @@ -15,14 +15,14 @@ BEGIN { use Moose; has 'counter' => ( - metaclass => 'Counter', + traits => [ 'Counter' ], is => 'ro', isa => 'Int', default => sub { 0 }, - provides => { - inc => 'inc_counter', - dec => 'dec_counter', - reset => 'reset_counter', + handles => { + inc_counter => 'inc', + dec_counter => 'dec', + reset_counter => 'reset', } ); } diff --git a/t/070_attribute_helpers/207_trait_string.t b/t/070_attribute_helpers/207_trait_string.t index bd23c99..69646dc 100644 --- a/t/070_attribute_helpers/207_trait_string.t +++ b/t/070_attribute_helpers/207_trait_string.t @@ -106,5 +106,5 @@ is_deeply($string->handles, { exclaim => [ append => [ '!' ] ], capitalize_last => [ replace => [ qr/(.)$/, $uc ] ], invalid_number => [ match => [ qr/\D/ ] ], -}, '... got the right provides methods'); +}, '... got the right handles methods');