- added list_all_type_constraints and
list_all_builtin_type_constraints
functions to facilitate introspection.
+
+ * Moose::Meta::Attribute
+ - fixed regexp 'handles' declarations
+ to build the list of delegated methods
+ correctly (and not override important
+ things like &new)
+ - added tests and docs for this
+
+ * misc.
+ - added test for working with Module::Refresh
0.18 Sat. March 10, 2007
~~ Many, many documentation updates ~~
t/102_Moose_Object_error.t
t/103_subclass_use_base_bug.t
t/104_inline_reader_bug.t
+t/105_module_refresh_compat.t
+t/106_handles_foreign_class_bug.t
t/201_example.t
t/202_example_Moose_POOP.t
t/203_example.t
=item I<handles =E<gt> [ @handles ]>
-There is experimental support for attribute delegation using the C<handles>
-option. More docs to come later.
+...
=back
use Scalar::Util 'blessed', 'weaken', 'reftype';
use Carp 'confess';
-our $VERSION = '0.09';
+our $VERSION = '0.10';
our $AUTHORITY = 'cpan:STEVAN';
use Moose::Meta::Method::Accessor;
(!$associated_class->has_method($handle))
|| confess "You cannot overwrite a locally defined method ($handle) with a delegation";
+ # NOTE:
+ # handles is not allowed to delegate
+ # any of these methods, as they will
+ # override the ones in your class, which
+ # is almost certainly not what you want.
+ next if $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle);
+
if ((reftype($method_to_call) || '') eq 'CODE') {
$associated_class->add_method($handle => $method_to_call);
}
($self->has_type_constraint)
|| confess "Cannot delegate methods based on a RegExpr without a type constraint (isa)";
return map { ($_ => $_) }
- grep { $handles } $self->_get_delegate_method_list;
+ grep { /$handles/ } $self->_get_delegate_method_list;
}
elsif (ref($handles) eq 'CODE') {
return $handles->($self, $self->_find_delegate_metaclass);
use Carp 'confess';
use Scalar::Util 'weaken', 'blessed', 'reftype';
-our $VERSION = '0.10';
+our $VERSION = '0.11';
our $AUTHORITY = 'cpan:STEVAN';
use Moose::Meta::Method::Overriden;
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 8;
+use Test::Exception;
+
+{
+ package Foo;
+
+ sub new {
+ bless({}, 'Foo')
+ }
+
+ sub a { 'Foo::a' }
+}
+
+{
+ package Bar;
+ use Moose;
+
+ ::lives_ok {
+ has 'baz' => (
+ is => 'ro',
+ isa => 'Foo',
+ lazy => 1,
+ default => sub { Foo->new() },
+ handles => qr/^a$/,
+ );
+ } '... can create the attribute with delegations';
+
+}
+
+my $bar;
+lives_ok {
+ $bar = Bar->new;
+} '... created the object ok';
+isa_ok($bar, 'Bar');
+
+is($bar->a, 'Foo::a', '... got the right delgated value');
+
+{
+ package Baz;
+ use Moose;
+
+ ::lives_ok {
+ has 'bar' => (
+ is => 'ro',
+ isa => 'Foo',
+ lazy => 1,
+ default => sub { Foo->new() },
+ handles => qr/.*/,
+ );
+ } '... can create the attribute with delegations';
+
+}
+
+my $baz;
+lives_ok {
+ $baz = Baz->new;
+} '... created the object ok';
+isa_ok($baz, 'Baz');
+
+is($baz->a, 'Foo::a', '... got the right delgated value');
+
+
+
+
+
+
+
+