Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

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

He may be missed, but his code won't be. He has a public SVN repository which is open access. If he was still with us today, I'm sure he'd be glad to know that someone wrote this piece of code ... so that we may not lose any of his gifts.

This one's for you, spoon.

#!/usr/bin/perl -w use strict; use POE; use POE::Component::Client::UserAgent; use XML::Sablotron::DOM; use URI; my @urls = qw(; my $thread = 0; sub _start { $_[HEAP]->{situa} = new XML::Sablotron::Situation(); $_[HEAP]->{alias} = "useragent".$_[ARG0]; $_[HEAP]->{thread} = ++$thread; POE::Component::Client::UserAgent->new (alias => $_[HEAP]->{alias}); $_[KERNEL]->yield("next"); } sub next { if (my $url = pop @urls) { $_[HEAP]->{url} = URI->new($url); print "Thread $_[HEAP]->{thread} fetching $url\n"; $_[KERNEL]->post ( $_[HEAP]->{alias} => "request", { request => HTTP::Request->new(GET => $url), response => $_[SESSION]->postback('got_it') } ); } else { print "Thread $_[HEAP]->{thread} waiting 10s for more work\n"; $_[KERNEL]->delay(waiting => 10); } } sub waiting { if (@urls) { goto \&next; } else { print "Thread $_[HEAP]->{thread} shutting down\n"; $_[KERNEL]->post ( $_[HEAP]->{alias} => "shutdown", ); } } sub got_it { my (undef, $response) = @{$_[ARG1]}; # write the response to a file my $url = $_[HEAP]->{url}; # pick a filename like wget does (my $filename = $url) =~ s{^http://}{}; my ($dirname) = ($filename =~ m{(.*)/[^/]*}); ( -d $dirname ) || system("mkdir -p '$dirname'"); if ($response->is_success) { if ($url =~ m{/$}) { print "Thread $_[HEAP]->{thread} scanning $url\n"; # a directory - grok it with Sablotron $_[HEAP]->{doc} = XML::Sablotron::DOM::parseBuffer ($_[HEAP]->{situa}, $response->content); my @dir_nodes = @{ $_[HEAP]->{doc}->xql("//dir") || []}; for my $node (@dir_nodes) { push @urls, URI->new_abs($node->getAttribute("href"), $url) } my @file_nodes = @{ $_[HEAP]->{doc}->xql("//file") || []}; for my $node (@file_nodes) { push @urls, URI->new_abs($node->getAttribute("href"), $url) } } else { # write response ... if (open FOO, ">$filename") { print "Thread $_[HEAP]->{thread} saving $url to $filename\ +n"; print FOO $response->content; close FOO; } else { warn "failed to open $filename for writing; $!"; }; } } else { warn "Thread $_[HEAP]->{thread} got error loading $url; " .$response->status_line."\n"; } $_[KERNEL]->yield("next"); } for (1..3) { POE::Session -> create ( inline_states => { _start => \&_start, next => \&next, got_it => \&got_it, waiting => \&waiting, }, args => [ $_ ], # arguments ); } $poe_kernel->run();
$h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";

In reply to Re: Iain Campbell Truskett ("Spoon"/"Koschei") RIP 2003-12-29 by mugwumpjism
in thread Iain Campbell Truskett ("Spoon"/"Koschei") RIP 2003-12-29 by merlyn

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (3)
    As of 2020-02-25 21:48 GMT
    Find Nodes?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?

      Results (113 votes). Check out past polls.