WWW::Agent::Zombie - Walking through websites like a zombie


WWW-Agent documentation Contained in the WWW-Agent distribution.

Index


Code Index:

NAME

Top

WWW::Agent::Zombie - Walking through websites like a zombie

SYNOPSIS

Top

  use WWW::Agent::Zombie;
  my $z = new WWW::Agent::Zombie ();
  $z->run (q{...
           # some WeeZL here
           });

DESCRIPTION

Top

This package provides a way to let zombies stalk the earth. Seriously, a plan (written in WeeZL, a simple text language, see WWW::Agent::Plugins::Director) controls a WWW::Agent object.

INTERFACE

Top

Constructor

The constructor expects a hash with the following key/value pairs:

functions (hash reference, optional):

In a WeeZL script you can refer to functions which you can provide here. The keys are the names of the functions as the can appear in the WeeZL script, as values you have to pass in subroutine references.

When such a subroutine is invoked, it will get the current context as parameter. See WWW::Agent::Plugins::Director for details.

Example:

   my $zombie = new WWW::Agent::Zombie (functions => {
                                            'test' => sub {
                                                  warn "here I am";
                                                  }
                                            'test2' => sub {
                                                  warn "and again";
                                                  },
                                                      });

time_dither (string, percentation number, optional)

In WeeZL scripts you can ask the agent to pause for a time interval. If you specify there ~ 4 secs (wait for approximately 5 seconds), then the time dither factor controls, what approximately means.

In case of 20%, the actual waiting time will randomly range from 4 to 6 seconds.

The default is 10%.

Methods

run

This method expects a string with a script written in WeeZL. If that is missing, the default

   die "no plan to run"

will be used. Once this executes, obviously we return with an exception.

The method will not return until the WeeZL script has terminated. Any infinite loop there will be exactly that. If the WeeZL script contains execptions, these will be caught and re-raised into your application.

Example:

   $zombie->run (q{
		 goto http://www.example.org/
		 wait ~ 15 secs
		 goto http://www.example.org/login.php
                 });

AUTHOR

Top

Robert Barta, <rho@bigpond.net.au>

COPYRIGHT AND LICENSE

Top


WWW-Agent documentation Contained in the WWW-Agent distribution.
package WWW::Agent::Zombie;

use strict;
use warnings;

use Data::Dumper;
use POE;

sub new {
    my $class   = shift;
    my %options = @_;
    my $self    = bless {}, $class;

    $self->{functions}   = delete $options{functions}   || {};
    $self->{time_dither} = delete $options{time_dither} || '10%';
#    die "unsupported dithering spec '".$self->{time_dither}."'" unless $self->{time_dither} =~ /^(\d+)\%$/;
#    $self->{time_dither} = $1;
    $self->{ua}          = delete $options{ua};

    use WWW::Agent;
#	use WWW::Agent::Plugins::LWP;
    use WWW::Agent::Plugins::Focus;
#    use WWW::Agent::Plugins::History;
    use WWW::Agent::Plugins::Director;
    new WWW::Agent (ua      => $self->{ua},
		    plugins => [
#							    new WWW::Agent::Plugins::LWP,
				new WWW::Agent::Plugins::Focus,
#				new WWW::Agent::Plugins::History (length => 10),
				new WWW::Agent::Plugins::Director (time_dither => $self->{time_dither},
								   functions   => $self->{functions},
								   exception   => sub { $self->{exception} = shift; }),
				]);
    return $self;
}

sub run {
    my $self = shift;
    my $plan = shift || q|die "no plan to run"|;

    POE::Kernel->post ( 'agent', 'director_execute', 'zombie', $plan );
    POE::Kernel->run  ();

    die $self->{exception} if $self->{exception};                      # if POE ended with an exception, we raise it here
}

our $VERSION  = '0.04';
our $REVISION = '$Id: Zombie.pm,v 1.2 2005/03/19 05:08:17 rho Exp $';

1;

__END__