[pm-h] Moose question

Will Willis will.willis at gmail.com
Sat Dec 19 13:25:03 PST 2009


I'm using Moose to write a package that, among other things, connects to the
internet to fetch some content.

The way I have my object designed is that want one of the attributes to
contain a reference to a WWW::Mechanize object.

----the code---

#!/usr/bin/perl
use strict;
use Website;

my $web = Website->new(name => 'Google', url => 'http://www.google.com/');
print "My Website's name is " . $web->name . "\n";

print $web->get_content();


----the class---

package Website;
use Moose;
use WWW::Mechanize;

has '_mech' => ( is => 'rw' );
has 'name'  => ( is => 'rw', isa => 'Str', required => 1);
has 'url'   => (is => 'rw', isa => 'Str', required => 1);

sub get_content {
    my $self = shift;
    $self->_mech = WWW::Mechanize->new();
    $self->_mech->get($self->url);
    return $self->_mech->content;
}
1;

--- /end code --

That's not working , I get the following output/error:

My Website's name is Google
Can't modify non-lvalue subroutine call at Website.pm line 11.

Do I need to make the '_mech' attribute be a (isa) WWW::Mechanize object to
achieve this? I have no intention of exposing any of WWW::Mechanize's
functionality to the outside. I'm probably missing a small detail. Any help
would be appreciated.


-Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/mailman/private/houston/attachments/20091219/bbc01d91/attachment.html>


More information about the Houston mailing list