/usr/share/perl5/Cache/IOString.pm is in libcache-perl 2.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | =head1 NAME
Cache::IOString - wrapper for IO::String to use in Cache implementations
=head1 DESCRIPTION
This module implements a derived class of IO::String that handles access
modes and allows callback on close. It is for use by Cache implementations
and should not be used directly.
=cut
package Cache::IOString;
require 5.006;
use strict;
use warnings;
use IO::String;
our @ISA = qw(IO::String);
sub open {
my $self = shift;
my ($dataref, $mode, $close_callback) = @_;
return $self->new(@_) unless ref($self);
# check mode
my $read;
my $write;
if ($mode =~ /^\+?>>?$/) {
$write = 1;
$read = 1 if $mode =~ /^\+/;
}
elsif ($mode =~ /^\+?<$/) {
$read = 1;
$write = 1 if $mode =~ /^\+/;
}
$self->SUPER::open($dataref);
*$self->{_cache_read} = $read;
*$self->{_cache_write} = $write;
*$self->{_cache_close_callback} = $close_callback;
if ($write) {
if ($mode =~ /^\+?>>$/) {
# append
$self->seek(0, 2);
}
elsif ($mode =~ /^\+?>$/) {
# truncate
$self->truncate(0);
}
}
return $self;
}
sub close {
my $self = shift;
delete *$self->{_cache_read};
delete *$self->{_cache_write};
*$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};
}
sub pad {
my $self = shift;
return undef unless *$self->{_cache_write};
return $self->SUPER::pad(@_);
}
sub getc {
my $self = shift;
return undef unless *$self->{_cache_read};
return $self->SUPER::getc(@_);
}
sub ungetc {
my $self = shift;
return undef unless *$self->{_cache_read};
return $self->SUPER::ungetc(@_);
}
sub seek {
my $self = shift;
# call setpos if not writing to ensure a seek past the end doesn't extend
# the string. Probably should really return undef in that situation.
return $self->SUPER::setpos(@_) unless *$self->{_cache_write};
return $self->SUPER::seek(@_);
}
sub getline {
my $self = shift;
return undef unless *$self->{_cache_read};
return $self->SUPER::getline(@_);
}
sub truncate {
my $self = shift;
return undef unless *$self->{_cache_write};
return $self->SUPER::truncate(@_);
}
sub read {
my $self = shift;
return undef unless *$self->{_cache_read};
return $self->SUPER::read(@_);
}
sub write {
my $self = shift;
return undef unless *$self->{_cache_write};
return $self->SUPER::write(@_);
}
*GETC = \&getc;
*READ = \&read;
*WRITE = \&write;
*SEEK = \&seek;
*CLOSE = \&close;
1;
__END__
=head1 SEE ALSO
Cache::Entry, Cache::File, Cache::RemovalStrategy
=head1 AUTHOR
Chris Leishman <chris@leishman.org>
Based on work by DeWitt Clinton <dewitt@unto.net>
=head1 COPYRIGHT
Copyright (C) 2003-2006 Chris Leishman. All Rights Reserved.
This module is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
either expressed or implied. This program is free software; you can
redistribute or modify it under the same terms as Perl itself.
$Id: IOString.pm,v 1.3 2006/01/31 15:23:58 caleishm Exp $
=cut
|