Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Delegating to a role in Moose

by Dallaylaen (Chaplain)
on Jan 12, 2018 at 10:46 UTC ( [id://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

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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1207147]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-19 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found