WWW::Mechanize::Plugin::HelloWorld - a sample WWW::Mechanize::Pluggable plugin


WWW-Mechanize-Pluggable documentation Contained in the WWW-Mechanize-Pluggable distribution.

Index


Code Index:

NAME

Top

WWW::Mechanize::Plugin::HelloWorld - a sample WWW::Mechanize::Pluggable plugin

-head1 SYNOPSIS

  use WWW::Mechanize::Pluggable;
  # This module is automatically loaded into WWW::Mechanize::Pluggable

DESCRIPTION

Top

This module shows how to mess with the WWW::Mechanize object contained within the WWW::Mechanize::Pluggable object.

Further refinements are left to the reader. Note that the fields in the WWW::Mechanize::Pluggable object are also available to the plugins.

USAGE

Top

    my $mech = new WWW::Mechanize::Pluggable;
    $mech->hello_world;
    # $mech->content now eq 'hello world'

BUGS

Top

None known.

SUPPORT

Top

Contact the author at mcmahon@yahoo-inc.com.

AUTHOR

Top

	Joe McMahon
	mcmahon@yahoo-inc.com

COPYRIGHT

Top

SEE ALSO

Top

WWW::Mechanize::Pluggable, WWW::Mechanize

CLASS METHODS

Top

import

This function snags any 'helloworld' key-value pair off the use WWW::Mechanize line and sets the HELLO key to it.

Currently this uses a global variable in the WW::Mechanize::Pluggable namespace to capture the value. This is icky and should be replaced with something more elegant.

init

The init() function exports hello_world into the caller's namespace.

hello_world

Just a demonstration function; replaces the current content with 'hello world'. It should be noted that this is not going to pass most tests for "successfully fetched page" because WWW::Mechanize hasn't processed a valid request-response pair.


WWW-Mechanize-Pluggable documentation Contained in the WWW-Mechanize-Pluggable distribution.
package WWW::Mechanize::Plugin::HelloWorld;
use strict;
use warnings;

sub import {
  my ($class, %args) = @_;
  if (defined $args{'helloworld'}) {
    $WWW::Mechanize::Pluggable::HelloWorld = $args{'helloworld'};
  }
}

sub init {
  no strict 'refs';
  *{caller() . '::hello_world'} = \&hello_world;
}

sub hello_world {
   my ($self) = shift;
   $self->{Mech}->{content} = 'hello world';
   $self->{HELLO} = $WWW::Mechanize::Pluggable::HelloWorld;
}

1;