http://qs321.pair.com?node_id=1207171


in reply to Re^3: Delegating to a role in Moose
in thread Delegating to a role in Moose

In the documentation, it's made to look like you can extend or override methods provided by URI but from what I can tell it does nothing of the sort. Take this, for example, which emulates what is in the documentation:

{ package MyURIRole 0.000001; use Moose::Role; requires 'host'; requires 'path'; sub print_hi { my $s = shift; print "hi\n"; } } { package MyURI 0.000001; use Carp; use Moose; use URI; has 'uri' => ( is => 'ro', isa => 'URI', handles => 'MyURIRole', ); } #! /usr/bin/env perl use MyURI; use strict; use warnings; my $uri = MyURI->new( uri => URI->new('http://www.perl.com/the_path')) +; print $uri->host; print "\n"; print $uri->path; print "\n"; $uri->print_hi;

From the documentation's explanation, I would expect the $uri->print_hi to print out "hi". Instead, I get an error:

Can't locate object method "print_hi" via package "URI::http" at inline delegation in MyURI for uri->print_hi (attribute declared in MyURI.pm at line 7) line 18.

So I'm not sure why the documentation is suggesting that using a role name with handles is a good way to delegate when using another package like URI. What is to be gained from it? Am I missing something?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks