#!perl -Tw use warnings; use strict; use Test::More tests => 7; use URI::file; BEGIN { use_ok( 'WWW::Mechanize' ); } my $mech = WWW::Mechanize->new(); isa_ok( $mech, 'WWW::Mechanize' ); { package _::Clonable; sub init { bless \(my $x = '') } sub clone { my $clone = bless \(my $x = ${+shift}); $$clone .= 'clone' . shift; $clone; } } { package _::AutocloneObject; my $count = 0; sub init { my $c = $count + 1; # no-ops during cloning: $_[1]->add_handler(get_content => sub { $c }); $_[1]->use_plugin('_::False'); bless \++$count; } } { package _::True; sub init { ++our $count; 1 } } { package _::False; sub init { ++our $count; 0 } } ++$INC{"_/$_.pm"},$mech->use_plugin("_::$_") for qw/ False Clonable AutocloneObject True /; $mech->get(URI::file->new_abs( 't/area_link.html' )); $mech->_push_page_stack; is ${$mech->plugin('_::Clonable')}, 'clone' . $mech, 'plugin with clone method'; is ${$mech->plugin('_::AutocloneObject')}, 2, 'plugin object without clone method'; is $_::True::count, 2, 'non-object autocloning'; is $_::False::count, 1, 'no cloning for false plugins' . ' (and use_plugin is a no-op during cloning)'; is $mech->content, 1, 'add_handler becomes a no-op when cloning';