Subject: | Iteration bug? |
Hi there,
I had a strange problem concerning iteration. Asked in #perl-help and
was advised that it looked like a bug.
The scenario is: you have an array of @targets which get looped through
by the same cached $mech object.
- When the script is run the first time, obviously nothing in the cache.
- When the script is run the second time with the same @targets, all
$targets are retrieved from the cache, yay.
- But if you remove one of the $targets from the array and run the
script again, the $target Immediately After the one removed is no longer
retrieved from the cache.
- You can remove several $targets and the one following each of them
will not be retrieved from the cache.
See file attached. Also available under the kind auspices of jhannah at
http://github.com/jhannah/sandbox/blob/master/doubi/mech.pl (although
lines 37 and 38 here are irrelevant leftovers :s)
I'm on Strawberry Perl 5.10.1, using W:M:C 1.35.
Sorry if this turns out to be a mistake on my part.
Thanks!
Subject: | wwwMechCached_query.pl |
#! /usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Cached;
use HTML::TreeBuilder;
use Cache::FileCache;
#
# Run this script once as it is. Then, remove one of the $target's below, and re-run it.
# From the output you'll see that the entry Immediately After the removed entry is no
# longer retrieved from the cache.
#
my @targets = ( 'http://www.sheffieldhelpyourself.org.uk/full_search_new.asp?group=24231&searchname=', # 104 Holgate Road
'http://www.sheffieldhelpyourself.org.uk/full_search_new.asp?group=16469&searchname=', # Age Concern Sheffield
'http://www.sheffieldhelpyourself.org.uk/full_search_new.asp?group=19691&searchname=', # Access Space
'http://www.sheffieldhelpyourself.org.uk/full_search_new.asp?group=16440&searchname=', # Action for Stannington
'http://www.sheffieldhelpyourself.org.uk/full_search_new.asp?group=23009&searchname=', # Activity Sheffield Council
'http://www.sheffieldhelpyourself.org.uk/full_search_new.asp?group=24630&searchname=' # Activity Sheffield Over 50s
);
my $cache = new Cache::FileCache( { 'namespace' => 'shef',
'cache_root' => "./shef",
'cache_depth' => 8,
'default_expires' => '1d'
} );
my $mech = WWW::Mechanize::Cached->new( cache => $cache );
for( my $i = 0; $i <= $#targets ; $i++ ) {
# Prepare the tree...
my $tree = HTML::TreeBuilder->new;
$tree->parse( $mech->get( $targets[$i] )->content );
$tree->eof;
$tree->objectify_text();
# print the name of the organisation fetched in this iteration
print $tree->address("0.1.0.3.1.1.2.0.1.0.0.0")->attr('text') . ": ";
if( $mech->is_cached() ) { print "this WAS cached.\n" } else { print "this was NOT cached.\n" };
}
1;