| 1 | package WWW::Mechanize::Plugin::HelloWorld; | ||||||||||
| 2 | 12 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | WWW::Mechanize::Plugin::HelloWorld - a sample WWW::Mechanize::Pluggable plugin | ||||||||||
| 8 | |||||||||||
| 9 | -head1 SYNOPSIS | ||||||||||
| 10 | |||||||||||
| 11 | use WWW::Mechanize::Pluggable; | ||||||||||
| 12 | # This module is automatically loaded into WWW::Mechanize::Pluggable | ||||||||||
| 13 | |||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||
| 15 | |||||||||||
| 16 | This module shows how to mess with the C<WWW::Mechanize> object contained | ||||||||||
| 17 | within the C<WWW::Mechanize::Pluggable> object. | ||||||||||
| 18 | |||||||||||
| 19 | Further refinements are left to the reader. Note that the fields in the | ||||||||||
| 20 | C<WWW::Mechanize::Pluggable> object are also available to the plugins. | ||||||||||
| 21 | |||||||||||
| 22 | =head1 USAGE | ||||||||||
| 23 | |||||||||||
| 24 | my $mech = new WWW::Mechanize::Pluggable; | ||||||||||
| 25 | $mech->hello_world; | ||||||||||
| 26 | # $mech->content now eq 'hello world' | ||||||||||
| 27 | |||||||||||
| 28 | =head1 BUGS | ||||||||||
| 29 | |||||||||||
| 30 | None known. | ||||||||||
| 31 | |||||||||||
| 32 | =head1 SUPPORT | ||||||||||
| 33 | |||||||||||
| 34 | Contact the author at C<mcmahon@yahoo-inc.com>. | ||||||||||
| 35 | |||||||||||
| 36 | =head1 AUTHOR | ||||||||||
| 37 | |||||||||||
| 38 | Joe McMahon | ||||||||||
| 39 | mcmahon@yahoo-inc.com | ||||||||||
| 40 | |||||||||||
| 41 | =head1 COPYRIGHT | ||||||||||
| 42 | |||||||||||
| 43 | Copyright 2005 by Joe McMahon and Yahoo! | ||||||||||
| 44 | |||||||||||
| 45 | This program is free software; you can redistribute | ||||||||||
| 46 | it and/or modify it under the same terms as Perl itself. | ||||||||||
| 47 | |||||||||||
| 48 | The full text of the license can be found in the | ||||||||||
| 49 | LICENSE file included with this module. | ||||||||||
| 50 | |||||||||||
| 51 | =head1 SEE ALSO | ||||||||||
| 52 | |||||||||||
| 53 | L<WWW::Mechanize::Pluggable>, C<WWW::Mechanize> | ||||||||||
| 54 | |||||||||||
| 55 | =head1 CLASS METHODS | ||||||||||
| 56 | |||||||||||
| 57 | =head2 import | ||||||||||
| 58 | |||||||||||
| 59 | This function snags any 'helloworld' key-value pair off the | ||||||||||
| 60 | C<use WWW::Mechanize> line and sets the C<HELLO> key to it. | ||||||||||
| 61 | |||||||||||
| 62 | Currently this uses a global variable in the C<WW::Mechanize::Pluggable> | ||||||||||
| 63 | namespace to capture the value. This is icky and should be replaced | ||||||||||
| 64 | with something more elegant. | ||||||||||
| 65 | |||||||||||
| 66 | =cut | ||||||||||
| 67 | |||||||||||
| 68 | 11 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=2 SCAR=8.1
| |||||||||||
| 69 | 11 | my ($class, %args) = @_; | |||||||||
| 70 | 11 | ▶ | if (defined $args{'helloworld'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | $WWW::Mechanize::Pluggable::HelloWorld = $args{'helloworld'}; | |||||||||
| 72 | } | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | =head2 init | ||||||||||
| 76 | |||||||||||
| 77 | The C<init()> function exports C<hello_world> into the caller's namespace. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | 12 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 82 | 12 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 83 | 12 | *{caller() . '::hello_world'} = \&hello_world; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | =head2 hello_world | ||||||||||
| 87 | |||||||||||
| 88 | Just a demonstration function; replaces the current content with 'hello world'. | ||||||||||
| 89 | It should be noted that this is not going to pass most tests for "successfully | ||||||||||
| 90 | fetched page" because C<WWW::Mechanize> hasn't processed a valid | ||||||||||
| 91 | request-response pair. | ||||||||||
| 92 | |||||||||||
| 93 | =cut | ||||||||||
| 94 | |||||||||||
| 95 | 0 | ▶ | sub hello_world { | ||||||||
|
Subroutine
hello_world: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 96 | 0 | my ($self) = shift; | |||||||||
| 97 | 0 | $self->{Mech}->{content} = 'hello world'; | |||||||||
| 98 | 0 | $self->{HELLO} = $WWW::Mechanize::Pluggable::HelloWorld; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 12 | 1; | |||||||||