Cache::File::Handle - wrapper for IO::File to use in Cache::File implementation


Cache documentation Contained in the Cache distribution.

Index


Code Index:

NAME

Top

Cache::File::Handle - wrapper for IO::File to use in Cache::File implementation

DESCRIPTION

Top

This module implements a derived class of IO::File that allows callback on close. It is for use by Cache::File and should not be used directly.

SEE ALSO

Top

Cache::File

AUTHOR

Top

 Chris Leishman <chris@leishman.org>
 Based on work by DeWitt Clinton <dewitt@unto.net>

COPYRIGHT

Top


Cache documentation Contained in the Cache distribution.
package Cache::File::Handle;

require 5.006;
use strict;
use warnings;
use IO::File;

our @ISA = qw(IO::File);


sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my ($filename, $mode, $perms, $close_callback) = @_;

    my $self = $class->SUPER::new($filename, $mode, $perms)
        or return undef;
    bless $self, $class;
    *$self->{_cache_close_callback} = $close_callback;

    return $self;
}

sub open {
    my $self = shift;
    my ($filename, $mode, $perms, $close_callback) = @_;

    *$self->{_cache_close_callback} = $close_callback;

    return $self->SUPER::open($filename, $mode, $perms);
}

sub close {
    my $self = shift;
    $self->flush;
    *$self->{_cache_close_callback}->($self) if *$self->{_cache_close_callback};
    delete *$self->{_cache_close_callback};
    $self->SUPER::close(@_);
}

sub DESTROY {
    my $self = shift;
    *$self->{_cache_close_callback}->($self) if *$self->{_cache_close_callback};
    #$self->SUPER::DESTROY();
}


1;
__END__