WWW::CheckSite::Util - provide utilities for WWW::CheckSite


WWW-CheckSite documentation Contained in the WWW-CheckSite distribution.

Index


Code Index:

NAME

Top

WWW::CheckSite::Util - provide utilities for WWW::CheckSite

SYNOPSIS

Top

    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 );




new_cache

Return a new WWW::CheckSite::Util::Cache object.

new_stack

Return a new WWW::CheckSite::Util::Stack object.

WWW::CheckSite::Util::Cache

Top

Implements a simple cache as a hash. Storage and reteival on the keyvalue.

set( $key => $data )

Add (or update) the cache for this key. Returns $data.

unset( $key )

Remove the item for this key from the cache.

has( $key )

Return the data if the exists otherwise return undef.

WWW::CheckSite::Util::Stack

Top

Implements a simple "Last in First out" stack. (They're called arrays in Perl :-)

push( $data )

Push $data onto the stack.

pop

Return the last data pushed onto the stack.

peek

Return the last item on the stack without popping it.

size

Return the size of the stack.

COPYRIGHT

Top


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;
}