Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 45223
Status: resolved
Priority: 0/
Queue: Moose

People
Owner: stevan.little [...] gmail.com
Requestors: perl [...] evancarroll.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Handles on ClassName attribute
Handles should work on Classname attributes for things like Storable FreezeThaw and YAML
Subject: moose_attribute_classname_handles.t
## ClassName should permit delegation based on class-functions ## As in the case of Storable/FreezeThaw and YAML, and Digest::* package K; use Storable; package Class; use Moose; has 'foobar' => ( isa => 'ClassName' , is => 'ro' , handles => [qw/freeze thaw/] ); package ClassS; use Moose; has 'foobar' => ( isa => 'ClassName' , is => 'ro' , handles => [qw/freeze thaw/] , lazy => 1 , default => 'Storable' ); package main; use Test::More tests => 2; eval { Class->new({ foobar => 'Storable' })->freeze( [qw/foo bar abz/] ); }; unlike ( $@, qr/not a reference/, "Handles on ClassName" ); eval { ClassS->new->freeze( [qw/foo bar abz/] ); }; ok ( ! defined $@, "Handles on ClassName (lazy)" );
Evan, Thanks for the suggestion, but I don't think this feature would work. To start with, both your examples are delegating to functions and not to methods. Delegation (as Moose defines it) is via method calls and not functions, so your proposed feature and your use case are in conflict. Second of all, we cannot tell the difference between class methods, class functions and instance methods, so it would be really hard for this feature to work properly without doing more then it should or perhaps the wrong thing. And lastly, we need to be able to know the methods we are delegating to at compile time in order to support the Regexp, Ducktype and CodeRef version of handles. We can not know this if the thing being delegated to is not yet defined. In short, this doesn't really fit into the existing delegation model in Moose at all, and it would have to have major caveats in order to do so, which is not acceptable for a core feature. It would make a decent MooseX:: module though, please feel free to write it. - Stevan