| WWW-CheckSite documentation | Contained in the WWW-CheckSite distribution. |
WWW::CheckSite::Util - provide utilities for WWW::CheckSite
use WWW::CheckSite::Util;
my $cache = new_cashe;
my $data;
if ( $data = $cache->has( $key ) ) { # $data is a *copy*
# change $data
$cache->set( $key => $data );
} else {
# set $data
$cache->set( $key => $data );
}
my $stack = new_stack( @sfields );
Return a new WWW::CheckSite::Util::Cache object.
Return a new WWW::CheckSite::Util::Stack object.
Implements a simple cache as a hash. Storage and reteival on the keyvalue.
Add (or update) the cache for this key. Returns $data.
Remove the item for this key from the cache.
Return the data if the exists otherwise return undef.
Implements a simple "Last in First out" stack. (They're called arrays in Perl :-)
Push $data onto the stack.
Return the last data pushed onto the stack.
Return the last item on the stack without popping it.
Return the size of the stack.
| WWW-CheckSite documentation | Contained in the WWW-CheckSite distribution. |
package WWW::CheckSite::Util; use strict; # $Id: Util.pm 428 2005-11-10 09:13:25Z abeltje $ use vars qw( $VERSION @EXPORT ); $VERSION = '0.002';
use base 'Exporter'; @EXPORT = qw( &new_cache &new_stack );
sub new_cache { return WWW::CheckSite::Util::Cache->new; }
sub new_stack { return WWW::CheckSite::Util::Stack->new; } package WWW::CheckSite::Util::Cache;
sub new { my $class = shift; return bless { }, $class; }
sub set { my( $self, $key, $data ) = @_; $self->{ $key } = $data; }
sub unset { my( $self, $key ) = @_; delete $self->{ $key }; }
sub has { my( $self, $key ) = @_; return exists $self->{ $key } ? $self->{ $key } : undef; } package WWW::CheckSite::Util::Stack;
sub new { return bless [ ], shift; }
sub push { my( $self, $data ) = @_; push @$self, $data; }
sub pop { my $self = shift; return @$self ? pop @$self : undef; }
sub peek { my $self = shift; return @$self ? $self->[-1] : undef; }
sub size { my $self = shift; return scalar @$self; }