Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Delegating to a role in Moose

by Dallaylaen (Hermit)
on Jan 12, 2018 at 10:46 UTC ( #1207147=note: print w/replies, xml ) Need Help??

in reply to Delegating to a role in Moose

Hello nysus,

It looks like you can't have with "Foo"; in your class and handles "Foo"; in an attribute at the same time, which is quite natural - you either impersonate a role, or point to someone else performing it for you. You have to choose.

I'm new to Moose, though. Take my advice with a grain of salt.

Hope that helps.

UPD: a minimal example

==> <== #!/usr/bin/env perl use strict; use warnings; use Foo; print Foo->new->bar, "\n"; ==> <== package Foo; use Moose; with "Roo"; use Goo; has goo => is => "rw", isa => "Roo", handles => "Roo" , default => sub { Goo->new; }; 1; ==> <== package Goo; use Moose; with "Roo"; 1; ==> <== package Roo; use Moose::Role; sub bar { 42 }; 1;

This doesn't work. One needs to comment out either "with", or "handles" in for the perl -I. to output 42 correctly.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1207147]
and the grasshoppers chirp...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2018-06-19 23:11 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.