Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The main reasons I like/use Moo, etc, are to share behavior in a larger application (like a Catalyst application where the model is needed by the controllers, the tests, and the command line) and to wrap up, normalize, and auto-document, complex behaviors of conjoined simple parts that would otherwise quickly become spaghetti; make things like push and @{$object->{bunch_of_data}} semantic, less dense. This web spider stub is off the top of my head so take it as a terse draft but it shows the kinds of things I like to do–

package MooSpider; use Moo; use MooX::HandlesVia; use Carp; our $VERSION = "42"; has "_pages" => is => "ro", handles_via => "Array", default => sub { [] }, handles => { pages => "elements", queue_page => "push", next_page => "shift", }; has "agent" => is => "lazy", isa => sub { confess "Need a flavor of WWW::Mechanize" unless eval { $_[0]->isa("WWW::Mechanize") } }, handles => [qw/ get post request links uri success response /]; sub _build_agent { require WWW::Mechanize; WWW::Mechanize->new( autocheck => 0, agent => join("/", __PACKAGE__, $VERSION) ); } sub crawl { my $self = shift; return unless my $uri = shift || $self->next_page; if ( $self->get($uri) and $self->success ) { $self->queue_page($_->url_abs) for $self->links; } else { carp "Problem fetching ", $self->uri, $/, "Moving on to next link"; $self->crawl; } $self->response; } 1; my $spider = MooSpider->new; $spider->crawl(""); print join($/, $spider->pages), $/; $spider->crawl; print join($/, $spider->pages), $/;

In reply to Re^3: Bullish on Moose, how about you? by Your Mother
in thread Bullish on Moose, how about you? by nysus

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2022-12-05 22:07 GMT
Find Nodes?
    Voting Booth?

    No recent polls found