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?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|