On Wed, Mar 14, 2012 at 02:22:11PM -0300, Marcos Barbeitos wrote:
> Howdy moosers, if I try to use the following package:
> 
> --
> package Test_Handle;
> 
> use Moose;
> use MooseX::StrictConstructor;
> 
> use DBIx::Custom;
> 
> has 'dbix_custom' =>
> (
>     is => 'ro'
>   , isa => 'DBIx::Custom'
>   , lazy_build => 1
>   , handles => qr/.+/
> );
> __PACKAGE__->meta->make_immutable;
> 1;
> 
> --
> perl -e 'use Test_Handle'
> --
> 
> I get:
> 
> Can't use string ("Test_Handle") as a HASH ref while "strict refs" in
> use at reader Test_Handle::dbix_custom (defined at Test_Handle.pm line
> 8) line 5.
> BEGIN failed--compilation aborted at -e line 1.
> 
> However, if I try to delegate a single method:
> 
> --
> package Test_Handle;
> 
> use Moose;
> use MooseX::StrictConstructor;
> 
> use DBIx::Custom;
> 
> has 'dbix_custom' =>
> (
>     is => 'ro'
>   , isa => 'DBIx::Custom'
>   , lazy_build => 1
>   , handles => qr/update/
> );
> __PACKAGE__->meta->make_immutable;
> 1;
> 
> --
> perl -e 'use Test_Handle'
> --
> 
> It works. Any ideas?  Thanks!

You're delegating the 'import' method from Object::Simple, so when you
do "use Test_Handle", it's calling Test_Handle->import, which tries to
delegate to Test_Handle->dbix_custom->import, which fails, since you
can't call an attribute accessor on a class name. This sort of thing is
why "handles => qr/.+/" is typically a pretty bad idea.

-doy

Reply via email to