use Carp ();
use Mouse::Meta::TypeConstraint;
-use Mouse::Meta::Method::Accessor;
+
+#use Mouse::Meta::Method::Accessor;
+use Mouse::Meta::Method::Delegation;
sub _process_options{
return;
}
+
+sub delegation_metaclass() { 'Mouse::Meta::Method::Delegation' }
+
sub install_accessors{
my($attribute) = @_;
# install delegation
if(exists $attribute->{handles}){
+ my $delegation_class = $attribute->delegation_metaclass;
my %handles = $attribute->_canonicalize_handles($attribute->{handles});
my $reader = $attribute->get_read_method_ref;
while(my($handle_name, $method_to_call) = each %handles){
- my $code = $accessor_class->_generate_delegation($attribute, $metaclass,
+ my $code = $delegation_class->_generate_delegation($attribute, $metaclass,
$reader, $handle_name, $method_to_call);
$metaclass->add_method($handle_name => $code);
};
}
-sub _generate_delegation{
- my (undef, $attribute, $class, $reader, $handle_name, $method_to_call) = @_;
-
- return sub {
- my $instance = shift;
- my $proxy = $instance->$reader();
-
- my $error = !defined($proxy) ? ' is not defined'
- : ref($proxy) && !blessed($proxy) ? qq{ is not an object (got '$proxy')}
- : undef;
- if ($error) {
- $instance->meta->throw_error(
- "Cannot delegate $handle_name to $method_to_call because "
- . "the value of "
- . $attribute->name
- . $error
- );
- }
- $proxy->$method_to_call(@_);
- };
-}
-
-
1;
__END__
--- /dev/null
+package Mouse::Meta::Method::Delegation;
+use Mouse::Util; # enables strict and warnings
+use Scalar::Util qw(blessed);
+
+sub _generate_delegation{
+ my (undef, $attribute, $metaclass, $reader, $handle_name, $method_to_call) = @_;
+
+ return sub {
+ my $instance = shift;
+ my $proxy = $instance->$reader();
+
+ my $error = !defined($proxy) ? ' is not defined'
+ : ref($proxy) && !blessed($proxy) ? qq{ is not an object (got '$proxy')}
+ : undef;
+ if ($error) {
+ $instance->meta->throw_error(
+ "Cannot delegate $handle_name to $method_to_call because "
+ . "the value of "
+ . $attribute->name
+ . $error
+ );
+ }
+ $proxy->$method_to_call(@_);
+ };
+}
+
+
+1;
+__END__
+
+=head1 NAME
+
+Mouse::Meta::Method::Delegation - A Mouse method generator for delegation methods
+
+=head1 VERSION
+
+This document describes Mouse version 0.40_01
+
+=head1 SEE ALSO
+
+L<Moose::Meta::Method::Delegation>
+
+=cut
package
Mouse::Meta::Attribute;
+use Mouse::Meta::Method::Accessor;
# readers
MODULE = Mouse PACKAGE = Mouse::Meta::Method::Accessor::XS
-BOOT:
-{
- AV* const isa = get_av("Mouse::Meta::Method::Accessor::XS::ISA", TRUE);
- av_push(isa, newSVpvs("Mouse::Meta::Method::Accessor"));
-}
-
CV*
_generate_accessor(klass, SV* attr, metaclass)
CODE: