blib/lib/PerlX/Window.pm

filter: Statementstmt 39.3% 26 / 66 Branchbran 0.0% 0 / 18 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 53.3% 8 / 15 Podpod n/a totaltotal 33.0% 36 / 109 CC 12 SCAR 20.1
CC
12
Cov
31%
_setup_magic_string
20.0
_setup_magic_array
12.0
window
12.0
CRAP 7.5
↑ Summary
1 1 ▶use 5.016000;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package PerlX::Window;
6  
7 our $AUTHORITY = 'cpan:TOBYINK';
8 our $VERSION = '0.004';
9  
10 1 ▶use Data::Alias;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Exporter::Shiny (our @EXPORT = qw( window window_pos ));
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=13.1
15 1 my $impl;
16 1 ▶ $impl ||= eval { require Hash::FieldHash; 'Hash::FieldHash' };
Condition33%1/3
$impl ||= eval { do { require Hash::FieldHash; "Hash::FieldHash" } }
l!l&&r!l&&!r
010
MC/DC0%0/2
$impl ||= eval { do { require Hash::FieldHash; "Hash::FieldHash" } }
$impl eval { do { require Hash::FieldHash; "Hash::FieldHash" } }
Truth table33%1/3
A ||= B
A= $implB= eval { do { require Hash::FieldHash; "Hash::FieldHash" } }
ABresult
1X1
011
000
17 0 ▶ $impl ||= do { require Hash::Util::FieldHash; 'Hash::Util::FieldHash' };
Condition33%1/3
$impl ||= do { require Hash::Util::FieldHash; "Hash::Util::FieldHash" }
l!l&&r!l&&!r
100
MC/DC0%0/2
$impl ||= do { require Hash::Util::FieldHash; "Hash::Util::FieldHash" }
$impl do { require Hash::Util::FieldHash; "Hash::Util::FieldHash" }
Truth table33%1/3
A ||= B
A= $implB= do { require Hash::Util::FieldHash; "Hash::Util::FieldHash" }
ABresult
1X1
011
000
18 1 $impl->import('fieldhash');
19 };
20  
21 our ($window, @window);
22  
23 sub _exporter_validate_opts
24 0 ▶{
Subroutine _exporter_validate_opts: not called CC=2 SCAR=14.2
25 0 my $me = shift;
26 0 my ($opts) = @_;
27
28 0 ▶ return if ref $opts->{into};
Branch: 1 branch
BranchTrueFalseTotal
if ref $$opts{"into"} 0 0 0
29
30 1 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 0 *{$opts->{into} . "::window"} = \(my $tmp);
32 0 *{$opts->{into} . "::window"} = [];
33 0 $me->_setup_magic_string(\${$opts->{into} . "::window"});
34 0 $me->_setup_magic_array(\@{$opts->{into} . "::window"});
35 }
36  
37 my $scalar_wiz;
38 sub _setup_magic_string
39 0 ▶{
Subroutine _setup_magic_string: not called CC=4 SCAR=30.0
40 0 shift;
41 0 my ($ref) = @_;
42
43 0 ▶ if (eval { require Variable::Magic })
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Variable::Magic } }) { } 0 0 0
44 {
45 $scalar_wiz = Variable::Magic::wizard(
46 0 ▶ get => sub { ${$_[0]} = $window; 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 ▶ set => sub { $window = ${$_[0]}; 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 );
49 0 Variable::Magic::cast($ref, $scalar_wiz);
50 }
51 else
52 {
53 0 ▶ unless (exists(&PerlX::Window::_TieScalar::TIESCALAR))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists &PerlX::Window::_TieScalar::TIESCALAR) 0 0 0
54 {
55 0 ▶ eval q ~
Branch: 1 branch
BranchTrueFalseTotal
eval "\n\t\t\t\tpackage #\n\t\t\t\t\tPerlX::Window::_TieScalar;\n\t\t\t\tsub TIESCALAR { my \$tmp = undef; bless \\\$tmp, \$_[0] }\n\t\t\t\tsub FETCH { \$PerlX::Window::window }\n\t\t\t\tsub STORE { \$PerlX::Window::window = \$_[1] }\n\t\t\t\t1;\n\t\t\t" or die "Something went horribly wrong: $@" 0 0 0
56 package #
57 PerlX::Window::_TieScalar;
58 sub TIESCALAR { my $tmp = undef; bless \$tmp, $_[0] }
59 sub FETCH { $PerlX::Window::window }
60 sub STORE { $PerlX::Window::window = $_[1] }
61 1;
62 ~ or die("Something went horribly wrong: $@");
63 }
64 0 tie($$ref, 'PerlX::Window::_TieScalar');
65 }
66 }
67  
68 sub _setup_magic_array
69 0 ▶{
Subroutine _setup_magic_array: not called CC=3 SCAR=24.8
70 0 shift;
71 0 my ($ref) = @_;
72
73 0 ▶ unless (exists(&PerlX::Window::_TieArray::TIEARRAY))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists &PerlX::Window::_TieArray::TIEARRAY) 0 0 0
74 {
75 0 ▶ eval q ~
Branch: 1 branch
BranchTrueFalseTotal
eval "\n\t\t\tpackage #\n\t\t\t\tPerlX::Window::_TieArray;\n\t\t\tuse Carp;\n\t\t\tsub TIEARRAY { my \$tmp = undef; bless \\\$tmp, \$_[0] }\n\t\t\tsub STORE { \$PerlX::Window::window[ \$_[1] ] = \$_[2] }\n\t\t\tsub FETCH { \$PerlX::Window::window[ \$_[1] ] }\n\t\t\tsub FETCHSIZE { scalar \@PerlX::Window::window }\n\t\t\tsub STORESIZE { croak(\"Array has a fixed size\") }\n\t\t\tsub EXTEND { () }\n\t\t\tsub EXISTS { !!1 }\n\t\t\tsub DELETE { croak(\"Array element cannot be deleted\") }\n\t\t\tsub CLEAR { croak(\"Array has a fixed size\") }\n\t\t\tsub PUSH { croak(\"Array has a fixed size\") }\n\t\t\tsub POP { croak(\"Array has a fixed size\") }\n\t\t\tsub SHIFT { croak(\"Array has a fixed size\") }\n\t\t\tsub UNSHIFT { croak(\"Array has a fixed size\") }\n\t\t\tsub SPLICE { croak(\"Array has a fixed size\") }\n\t\t\t1;\n\t\t" or die "Something went horribly wrong: $@" 0 0 0
76 package #
77 PerlX::Window::_TieArray;
78 use Carp;
79 sub TIEARRAY { my $tmp = undef; bless \$tmp, $_[0] }
80 sub STORE { $PerlX::Window::window[ $_[1] ] = $_[2] }
81 sub FETCH { $PerlX::Window::window[ $_[1] ] }
82 sub FETCHSIZE { scalar @PerlX::Window::window }
83 sub STORESIZE { croak("Array has a fixed size") }
84 sub EXTEND { () }
85 sub EXISTS { !!1 }
86 sub DELETE { croak("Array element cannot be deleted") }
87 sub CLEAR { croak("Array has a fixed size") }
88 sub PUSH { croak("Array has a fixed size") }
89 sub POP { croak("Array has a fixed size") }
90 sub SHIFT { croak("Array has a fixed size") }
91 sub UNSHIFT { croak("Array has a fixed size") }
92 sub SPLICE { croak("Array has a fixed size") }
93 1;
94 ~ or die("Something went horribly wrong: $@");
95 }
96 0 tie(@$ref, 'PerlX::Window::_TieArray');
97 }
98  
99 fieldhash(my %pos);
100 my $last;
101  
102 0 ▶sub window (\[$@]$) :lvalue
Subroutine window: not called CC=3 SCAR=24.8
103 {
104 0 my ($ref, $n) = @_;
105
106 $pos{$ref} = -1
107 0 ▶ unless defined $pos{$ref};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos{$ref} 0 0 0
108
109 0 weaken( $last = $ref );
110 0 ++$pos{$ref};
111
112 0 ▶ ref($ref) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
113 ? _window_on_array(@_)
114 : _window_on_string(@_);
115 }
116  
117 0 ▶sub window_pos (;\[$@]) :lvalue
Subroutine window_pos: not called CC=2 SCAR=17.9
118 {
119 0 ▶ my ($ref) = @_ ? @_ : ($last);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
120 0 $pos{$ref};
121 }
122  
123 sub _window_on_array :lvalue
124 {
125 my ($ref, $n) = @_;
126 my $pos = $pos{$ref};
127
128 if ($pos + $n > scalar(@$ref))
129 {
130 alias( @window = () );
131 $pos{$ref} = undef;
132 return;
133 }
134
135 alias( @window = @{$ref}[$pos .. $pos+$n-1] );
136 @window;
137 }
138  
139 sub _window_on_string :lvalue
140 {
141 my ($ref, $n) = @_;
142 my $pos = $pos{$ref};
143
144 if ($pos + $n > length($$ref))
145 {
146 my $tmp = undef;
147 alias( $window = $tmp );
148 $pos{$ref} = undef;
149 return;
150 }
151
152 alias( $window = substr($$ref, $pos, $n) );
153 $window;
154 }
155  
156 1;
157  
158 __END__
↑ Summary