Revision history for Perl extension MooseX-AttributeHelpers
+0.06
+ * MooseX::AttributeHelpers::Base
+ - added the &remove_accessors method to comply with the
+ Class::MOP::Attribute interface
+ - added test for this
+ - the &install_accessors method now also properly assocaites
+ the methods with the attribute, so they are accessible via
+ introspection now.
+
0.05 Sat. Nov. 24, 2007
- update Class::MOP dependency
- - hide the Moose::Meta::Attribute::Custom::* package
+ - hide the Moose::Meta::Attribute::Custom::* package
declarations from search.cpan.org (when did they change
things to start seeing these?? *sigh*)
* MooseX::AttributeHelpers::Base
- changing this to use the new Class::MOP::Attribute
reader and write method ref stuff.
- - fixed this to use find_or_create_type_constraint
+ - fixed this to use find_or_create_type_constraint
instead of trying to parse stuff on our own.
-
+
* MooseX::AttributeHelpers::Collection
- - this is pretty much empty subclass now cause of
+ - this is pretty much empty subclass now cause of
the find_or_create_type_constraint fix above
-
+
+ MooseX::AttributeHelpers::Collection::ImmutableHash
+ MooseX::AttributeHelpers::Collection::Bag
- added these two new collection types
- added method provider roles for them
- added tests for them
-
+
* MooseX::AttributeHelpers::MethodProvider::Hash
- this is now composed from the ImmutableHash
method provider
-
+
* t/
- fixed the plans on all the tests
0.03 Mon. Sept. 17, 2007
~~ more misc. doc updates ~~
-
+
* MooseX::AttributeHelpers::Counter
- now provides default attribute options for 'is',
'isa', 'provides', and 'default' if not specified.
-
+
* MooseX::AttributeHelpers::Base
- added attribute $name to the params passed to
process_options_or_provides(), which gives us more
flexibility when writing additional helpers
- removed check for 'provides' and 'isa' attr
options before _process_options. It should be
- called always.
-
+ called always.
+
* MooseX::AttributeHelpers::MethodProvider::Array
- - added `delete` and `insert` methods
+ - added `delete` and `insert` methods
0.02 Thurs. Sept. 13, 2007
~~ some misc. doc updates ~~
* MooseX::AttributeHelpers::Base
- - now providing subrefs for the reader and writer
+ - now providing subrefs for the reader and writer
methods to all the method provider constructors
(this should speed things up quite a bit).
- all method providers now use this internally
* MooseX::AttributeHelpers::Counter
- - added the 'reset' method
-
+ - added the 'reset' method
+
* MooseX::AttributeHelpers::Collection::Array
- - Extracted the List method provider role from
+ - Extracted the List method provider role from
Array and made Array consume List.
+ MooseX::AttributeHelpers::Collection::List
- created the Collection::List metaclass
- derived from parts of the old Collection::Array
+ derived from parts of the old Collection::Array
0.01 Mon. Aug. 13, 2007
- module released to CPAN
use Moose;
use Moose::Util::TypeConstraints;
-our $VERSION = '0.03';
+our $VERSION = '0.04';
our $AUTHORITY = 'cpan:STEVAN';
extends 'Moose::Meta::Attribute';
);
-# these next two are the possible methods
+# these next two are the possible methods
# you can use in the 'provides' map.
-# provide a Class or Role which we can
-# collect the method providers from
+# provide a Class or Role which we can
+# collect the method providers from
has 'method_provider' => (
is => 'ro',
isa => 'ClassName',
# or you can provide a HASH ref of anon subs
# yourself. This will also collect and store
-# the methods from a method_provider as well
+# the methods from a method_provider as well
has 'method_constructors' => (
is => 'ro',
isa => 'HashRef',
# or grab them from the role/class
my $method_provider = $self->method_provider->meta;
return +{
- map {
+ map {
$_ => $method_provider->get_method($_)
} $method_provider->get_method_list
- };
+ };
},
);
-# extend the parents stuff to make sure
+# extend the parents stuff to make sure
# certain bits are now required ...
has '+$!default' => (required => 1);
has '+type_constraint' => (required => 1);
sub process_options_for_provides {
my ($self, $options) = @_;
-
+
if (my $type = $self->helper_type) {
(exists $options->{isa})
- || confess "You must define a type with the $type metaclass";
+ || confess "You must define a type with the $type metaclass";
- my $isa = $options->{isa};
+ my $isa = $options->{isa};
unless (blessed($isa) && $isa->isa('Moose::Meta::TypeConstraint')) {
- $isa = Moose::Util::TypeConstraints::find_or_create_type_constraint($isa);
+ $isa = Moose::Util::TypeConstraints::find_or_create_type_constraint($isa);
}
($isa->is_a_type_of($type))
## methods called after instantiation
-# this confirms that provides has
+# this confirms that provides has
# all valid possibilities in it
sub check_provides_values {
my $self = shift;
-
+
my $method_constructors = $self->method_constructors;
-
+
foreach my $key (keys %{$self->provides}) {
(exists $method_constructors->{$key})
|| confess "$key is an unsupported method type";
after 'install_accessors' => sub {
my $attr = shift;
my $class = $attr->associated_class;
-
+
# grab the reader and writer methods
- # as well, this will be useful for
+ # as well, this will be useful for
# our method provider constructors
my $attr_reader = $attr->get_read_method_ref;
my $attr_writer = $attr->get_write_method_ref;
-
+
# before we install them, lets
# make sure they are valid
- $attr->check_provides_values;
+ $attr->check_provides_values;
my $method_constructors = $attr->method_constructors;
-
+
foreach my $key (keys %{$attr->provides}) {
-
- my $method_name = $attr->provides->{$key};
-
+
+ my $method_name = $attr->provides->{$key};
+
if ($class->has_method($method_name)) {
confess "The method ($method_name) already exists in class (" . $class->name . ")";
- }
-
- my $method_body = $method_constructors->{$key}->(
- $attr,
- $attr_reader,
- $attr_writer,
- );
-
- $class->add_method($method_name =>
- MooseX::AttributeHelpers::Meta::Method::Provided->wrap(
- $method_body,
+ }
+
+ my $method = MooseX::AttributeHelpers::Meta::Method::Provided->wrap(
+ $method_constructors->{$key}->(
+ $attr,
+ $attr_reader,
+ $attr_writer,
)
);
+
+ $attr->associate_method($method);
+ $class->add_method($method_name => $method);
+ }
+};
+
+after 'remove_accessors' => sub {
+ my $attr = shift;
+ my $class = $attr->associated_class;
+ foreach my $key (keys %{$attr->provides}) {
+ my $method_name = $attr->provides->{$key};
+ my $method = $class->get_method($method_name);
+ $class->remove_method($method_name)
+ if blessed($method) &&
+ $method->isa('MooseX::AttributeHelpers::Meta::Method::Provided');
}
};
=head1 NAME
MooseX::AttributeHelpers::Base - Base class for attribute helpers
-
+
=head1 DESCRIPTION
Documentation to come.
=item B<install_accessors>
+=item B<remove_accessors>
+
=item B<process_options_for_provides>
=back
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
+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.