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

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

==> 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
Node Status?
node history
Node Type: note [id://1207147]
help
Chatterbox?
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
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (116 votes). Check out past polls.

    Notices?