use Carp 'confess';
use Scalar::Util 'blessed', 'weaken';
-our $VERSION = '0.85';
+our $VERSION = '0.93';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
|| confess
'You must supply a delegate_to_method which is a method name or a CODE reference';
+ exists $options{curried_arguments}
+ || ( $options{curried_arguments} = [] );
+
+ ( $options{curried_arguments} &&
+ ( 'ARRAY' eq ref $options{curried_arguments} ) )
+ || confess 'You must supply a curried_arguments which is an ARRAY reference';
+
my $self = $class->_new( \%options );
weaken( $self->{'attribute'} );
return bless $options, $class;
}
+sub curried_arguments { (shift)->{'curried_arguments'} }
+
sub associated_attribute { (shift)->{'attribute'} }
sub delegate_to_method { (shift)->{'delegate_to_method'} }
my $proxy = $instance->$accessor();
my $error
- = !defined $proxy ? ' is not defined'
- : !blessed $proxy ? qq{ is not an object (got '$proxy')}
- : undef;
+ = !defined $proxy ? ' is not defined'
+ : ref($proxy) && !blessed($proxy) ? qq{ is not an object (got '$proxy')}
+ : undef;
if ($error) {
$self->throw_error(
object => $instance
);
}
-
+ unshift @_, @{ $self->curried_arguments };
$proxy->$method_to_call(@_);
};
}
sub _get_delegate_accessor {
my $self = shift;
-
- my $accessor = $self->associated_attribute->get_read_method_ref;
-
- $accessor = $accessor->body if blessed $accessor;
+ my $attr = $self->associated_attribute;
+
+ # NOTE:
+ # always use a named method when
+ # possible, if you use the method
+ # ref and there are modifiers on
+ # the accessors then it will not
+ # pick up the modifiers too. Only
+ # the named method will assure that
+ # we also have any modifiers run.
+ # - SL
+ my $accessor = $attr->has_read_method
+ ? $attr->get_read_method
+ : $attr->get_read_method_ref;
+
+ $accessor = $accessor->body if Scalar::Util::blessed $accessor;
return $accessor;
}
The method in the associated attribute's value to which we
delegate. This can be either a method name or a code reference.
+=item I<curried_arguments>
+
+An array reference of arguments that will be prepended to the argument list for
+any call to the delegating method.
+
=back
=item B<< $metamethod->associated_attribute >>
Returns the attribute associated with this method.
+=item B<< $metamethod->curried_arguments >>
+
+Return any curried arguments that will be passed to the delegated method.
+
=item B<< $metamethod->delegate_to_method >>
Returns the method to which this method delegates, as passed to the
=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.
+See L<Moose/BUGS> for details on reporting bugs.
=head1 AUTHOR