blib/lib/PerlIO/via/Rotate.pm

filter: Statementstmt 63.3% 83 / 131 Branchbran 27.2% 18 / 66 Conditioncond 44.4% 4 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 86.6% 26 / 30 Podpod 0.0% 0 / 25 totaltotal 49.6% 132 / 266 CC 65 SCAR 16.1
CC
65
Cov
51%
import
33.1
WRITE
4.1
FILL
2.9
CRAP 5.0
↑ Summary
1 package PerlIO::via::Rotate;
2  
3 5 $VERSION= '0.11';
4  
5 # be strict and do everything on octets
6 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # initialize the base rotational strings
10 5 my @rotate= ( '', qw(
11 b-za
12 c-zab
13 d-za-c
14 e-za-d
15 f-za-e
16 g-za-f
17 h-za-g
18 i-za-h
19 j-za-i
20 k-za-j
21 l-za-k
22 m-za-l
23 n-za-m
24 o-za-n
25 p-za-o
26 q-za-p
27 r-za-q
28 s-za-r
29 t-za-s
30 u-za-t
31 v-za-u
32 w-za-v
33 x-za-w
34 yza-x
35 za-y
36 ), '' );
37  
38 # satisfy -require-
39 5 1;
40  
41 #-------------------------------------------------------------------------------
42 #
43 # Standard Perl features
44 #
45 #-------------------------------------------------------------------------------
46 # IN: 1 class to bless with
47 # 2..N parameters passed in -use-
48  
49 6 ▶sub import {
Subroutine import: called CC=12 SCAR=35.0
50 6 shift;
51  
52 # set up defaults
53 6 ▶ @_= 0..26 if @_ == 1 and $_[0] eq ':all';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and $_[0] eq ":all" 1 4 5
Condition66%2/3
@_ == 1 and $_[0] eq ":all"
!ll&&!rl&&r
401
MC/DC50%1/2
@_ == 1 and $_[0] eq ":all"
@_ == 1 $_[0] eq ":all"
Truth table66%2/3
A and B
A= @_ == 1B= $_[0] eq ":all"
ABresult
0X0
100
111
54 6 ▶ @_= 13 if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 3 2 5
55  
56 # process all rotations
57 6 my @huh;
58 ROTATION:
59 6 foreach (@_) {
60  
61 # huh?
62 34 ▶ push( @huh, "Invalid rotational value: $_" ), next ROTATION
Branch: 1 branch
BranchTrueFalseTotal
if not /^[0-9]+$/ or $_ < 0 or $_ > 26 0 33 33
Condition33%2/6
not /^[0-9]+$/ or $_ < 0 or $_ > 26
l!l&&r!l&&!r
0033
not /^[0-9]+$/ or $_ < 0
l!l&&r!l&&!r
0033
MC/DC0%0/3
not /^[0-9]+$/ or $_ < 0 or $_ > 26
not /^[0-9]+$/ $_ < 0 $_ > 26
Truth table25%1/4
not(A) or B or C
A= not /^[0-9]+$/B= $_ < 0C= $_ > 26
ABCresult
1XX1
01X1
0011
0000
63 if !m#^[0-9]+$# or $_ < 0 or $_ > 26;
64  
65 # we've already done this one
66 34 my $module= "PerlIO/via/rot$_.pm";
67 34 ▶ next ROTATION if $INC{$module};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$module} 0 33 33
68  
69 # source for the module
70 34 my $source= <<"SRC";
71 package PerlIO::via::rot$_;
72 use bytes;
73 \@PerlIO::via::rot$_\::ISA= 'PerlIO::via::Rotate';
74 \$PerlIO::via::rot$_\::VERSION= '$PerlIO::via::Rotate::VERSION';
75 SRC
76  
77 # we can do encoding for this
78 34 ▶ if ( my $encode= $rotate[$_] . uc( $rotate[$_] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $encode = $rotate[$_] . uc($rotate[$_])) 31 2 33
79 32 my $other= 26 - $_;
80 32 my $decode= $rotate[$other] . uc( $rotate[$other] );
81  
82 # add the source code for this rotation (PUSHED is inherited)
83 32 $source .= <<"SRC";
84 sub FILL {
85 local \$_= readline( \$_[1] );
86 return if !defined \$_;
87 tr/a-zA-Z/$decode/;
88 return \$_;
89 } #FILL
90 sub WRITE {
91 local \$_= \$_[1];
92 tr/a-zA-Z/$encode/;
93 return ( print { \$_[2] } \$_ ) ? length() : -1;
94 } #WRITE
95 SRC
96 }
97  
98 # make the module available and mark as loaded
99 0 ▶ if ( eval "$source; 1" ) {
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine FILL: called CC=2 SCAR=10.7
Subroutine WRITE: called CC=2 SCAR=10.7
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: not called CC=1 SCAR=2.1
Subroutine BEGIN: not called CC=1 SCAR=2.1
Subroutine BEGIN: not called CC=1 SCAR=2.1
Subroutine BEGIN: not called CC=1 SCAR=2.1
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 24 branches
BranchTrueFalseTotal
if (eval "$source; 1") { } 33 0 33
unless defined $_ 2 16 18
print({$_[2];} $_) ? : 3 8 11
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 1 8 9
unless defined $_ 1 0 1
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
unless defined $_ 0 0 0
100 34 $INC{$module}= $INC{'PerlIO/via/Rotate.pm'};
101 }
102  
103 # huh?
104 else {
105 1 push @huh, "Could not create module for $_: $@";
106 }
107 }
108  
109 # sorry, can't go on
110 6 ▶ die join "\n", "These errors were found:", @huh if @huh;
Branch: 1 branch
BranchTrueFalseTotal
if @huh 0 5 5
111  
112 6 return;
113 } #import
114  
115 #-------------------------------------------------------------------------------
116 # IN: 1 class
117 # 2 numeric value to check
118  
119 4 ▶sub VERSION { 1 } #VERSION
Subroutine VERSION: called CC=1 SCAR=0.0
Pod undocumented
120  
121 #-------------------------------------------------------------------------------
122 # IN: 1 class to bless with
123 # 2 mode string (ignored)
124 # 3 file handle of PerlIO layer below (ignored)
125 # OUT: 1 blessed object
126  
127 10 ▶sub PUSHED { bless \*PUSHED, $_[0] } #PUSHED
Subroutine PUSHED: called CC=1 SCAR=0.0
Pod undocumented
128  
129 #-------------------------------------------------------------------------------
130 # IN: 1 instantiated object (ignored)
131 # 2 handle to read from
132 # OUT: 1 decoded string
133  
134 1 ▶sub FILL {
Subroutine FILL: called CC=2 SCAR=7.1
Pod undocumented
135  
136 # huh?
137 2 local( $_ )= ref( $_[0] );
138 2 ▶ die "Class $_ was not activated" if !m#::rot(?:0|26)$#;
Branch: 1 branch
BranchTrueFalseTotal
unless /::rot(?:0|26)$/ 1 0 1
139  
140 1 return readline( $_[1] );
141 } #FILL
142  
143 #-------------------------------------------------------------------------------
144 # IN: 1 instantiated object (ignored)
145 # 2 buffer to be written
146 # 3 handle to write to
147 # OUT: 1 number of bytes written
148  
149 1 ▶sub WRITE {
Subroutine WRITE: called CC=3 SCAR=14.2
150  
151 # huh?
152 1 local( $_ ) = ref( $_[0] );
153 1 ▶ die "Class $_ was not activated" unless m#::rot(?:0|26)$#;
Branch: 1 branch
BranchTrueFalseTotal
unless /::rot(?:0|26)$/ 0 0 0
154  
155 1 ▶ return ( print { $_[2] } $_[1] ) ? length( $_[1] ) : -1;
Branch: 1 branch
BranchTrueFalseTotal
print({$_[2];} $_[1]) ? : 0 0 0
156 } #WRITE
157  
158 #-------------------------------------------------------------------------------
159  
160 __END__
↑ Summary