Cache/IOString.pm

filter: Statementstmt 82.0% 55 / 67 Branchbran 58.3% 21 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 10 / 14 Podpod 20.0% 2 / 10 totaltotal 69.2% 88 / 127 CC 19 SCAR 15.9
CC
19
Cov
74%
open
9.1
pad
6.0
getc
6.0
CRAP 4.9
« Cache/File/Handle.pm ↑ Summary Cache.pm »
1 =head1 NAME
2  
3 Cache::IOString - wrapper for IO::String to use in Cache implementations
4  
5 =head1 DESCRIPTION
6  
7 This module implements a derived class of IO::String that handles access
8 modes and allows callback on close. It is for use by Cache implementations
9 and should not be used directly.
10  
11 =cut
12 package Cache::IOString;
13  
14 3 require 5.006;
15 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use IO::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 3 our @ISA = qw(IO::String);
20  
21  
22 9 ▶sub open {
Subroutine open: called CC=9 SCAR=22.0
Pod documented
23 9 my $self = shift;
24 9 my ($dataref, $mode, $close_callback) = @_;
25 9 ▶ return $self->new(@_) unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 9 9
26  
27 # check mode
28 9 my $read;
29 my $write;
30 9 ▶ if ($mode =~ /^\+?>>?$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode =~ /^\+?>>?$/) { } 4 5 9
elsif ($mode =~ /^\+?<$/) { } 5 0 5
31 4 $write = 1;
32 4 ▶ $read = 1 if $mode =~ /^\+/;
Branch: 1 branch
BranchTrueFalseTotal
if $mode =~ /^\+/ 0 4 4
33 }
34 elsif ($mode =~ /^\+?<$/) {
35 5 $read = 1;
36 5 ▶ $write = 1 if $mode =~ /^\+/;
Branch: 1 branch
BranchTrueFalseTotal
if $mode =~ /^\+/ 3 2 5
37 }
38  
39 9 $self->SUPER::open($dataref);
40  
41 9 *$self->{_cache_read} = $read;
42 9 *$self->{_cache_write} = $write;
43 9 *$self->{_cache_close_callback} = $close_callback;
44  
45 9 ▶ if ($write) {
Branch: 1 branch
BranchTrueFalseTotal
if ($write) 7 2 9
46 7 ▶ if ($mode =~ /^\+?>>$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode =~ /^\+?>>$/) { } 2 5 7
elsif ($mode =~ /^\+?>$/) { } 2 3 5
47 # append
48 2 $self->seek(0, 2);
49 }
50 elsif ($mode =~ /^\+?>$/) {
51 # truncate
52 2 $self->truncate(0);
53 }
54 }
55  
56 9 return $self;
57 }
58  
59 8 ▶sub close {
Subroutine close: called CC=2 SCAR=6.9
Pod undocumented
60 8 my $self = shift;
61 8 delete *$self->{_cache_read};
62 8 delete *$self->{_cache_write};
63 8 ▶ *$self->{_cache_close_callback}->($self) if *$self->{_cache_close_callback};
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"_cache_close_callback"} 4 4 8
64 8 delete *$self->{_cache_close_callback};
65 8 $self->SUPER::close(@_);
66 }
67  
68 9 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.2
69 9 my $self = shift;
70 9 ▶ *$self->{_cache_close_callback}->($self) if *$self->{_cache_close_callback};
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"_cache_close_callback"} 0 9 9
71 }
72  
73 0 ▶sub pad {
Subroutine pad: not called CC=2 SCAR=17.9
Pod documented
74 0 my $self = shift;
75 0 ▶ return undef unless *$self->{_cache_write};
Branch: 1 branch
BranchTrueFalseTotal
unless *$self->{"_cache_write"} 0 0 0
76 0 return $self->SUPER::pad(@_);
77 }
78  
79 0 ▶sub getc {
Subroutine getc: not called CC=2 SCAR=17.9
Pod undocumented
80 0 my $self = shift;
81 0 ▶ return undef unless *$self->{_cache_read};
Branch: 1 branch
BranchTrueFalseTotal
unless *$self->{"_cache_read"} 0 0 0
82 0 return $self->SUPER::getc(@_);
83 }
84  
85 0 ▶sub ungetc {
Subroutine ungetc: not called CC=2 SCAR=17.9
Pod undocumented
86 0 my $self = shift;
87 0 ▶ return undef unless *$self->{_cache_read};
Branch: 1 branch
BranchTrueFalseTotal
unless *$self->{"_cache_read"} 0 0 0
88 0 return $self->SUPER::ungetc(@_);
89 }
90  
91 7 ▶sub seek {
Subroutine seek: called CC=2 SCAR=7.1
Pod undocumented
92 7 my $self = shift;
93 # call setpos if not writing to ensure a seek past the end doesn't extend
94 # the string. Probably should really return undef in that situation.
95 7 ▶ return $self->SUPER::setpos(@_) unless *$self->{_cache_write};
Branch: 1 branch
BranchTrueFalseTotal
unless *$self->{"_cache_write"} 0 7 7
96 7 return $self->SUPER::seek(@_);
97 }
98  
99 12 ▶sub getline {
Subroutine getline: called CC=2 SCAR=7.1
Pod undocumented
100 12 my $self = shift;
101 12 ▶ return undef unless *$self->{_cache_read};
Branch: 1 branch
BranchTrueFalseTotal
unless *$self->{"_cache_read"} 0 12 12
102 12 return $self->SUPER::getline(@_);
103 }
104  
105 2 ▶sub truncate {
Subroutine truncate: called CC=2 SCAR=7.1
Pod undocumented
106 2 my $self = shift;
107 2 ▶ return undef unless *$self->{_cache_write};
Branch: 1 branch
BranchTrueFalseTotal
unless *$self->{"_cache_write"} 0 2 2
108 2 return $self->SUPER::truncate(@_);
109 }
110  
111 0 ▶sub read {
Subroutine read: not called CC=2 SCAR=17.9
Pod undocumented
112 0 my $self = shift;
113 0 ▶ return undef unless *$self->{_cache_read};
Branch: 1 branch
BranchTrueFalseTotal
unless *$self->{"_cache_read"} 0 0 0
114 0 return $self->SUPER::read(@_);
115 }
116  
117 9 ▶sub write {
Subroutine write: called CC=2 SCAR=6.9
Pod undocumented
118 9 my $self = shift;
119 9 ▶ return undef unless *$self->{_cache_write};
Branch: 1 branch
BranchTrueFalseTotal
unless *$self->{"_cache_write"} 1 8 9
120 8 return $self->SUPER::write(@_);
121 }
122  
123 3 *GETC = \&getc;
124 3 *READ = \&read;
125 3 *WRITE = \&write;
126 3 *SEEK = \&seek;
127 3 *CLOSE = \&close;
128  
129  
130 3 1;
131 __END__
« Cache/File/Handle.pm ↑ Summary Cache.pm »