blib/lib/PerlIO/via/Skip.pm

filter: Statementstmt 29.0% 9 / 31 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 3 / 6 Podpod n/a totaltotal 20.0% 12 / 60 CC 12 SCAR 34.0
CC
12
Cov
17%
PUSHED
56.0
__ANON__
20.0
compile_patterns
12.0
CRAP 30.1
↑ Summary
1 package PerlIO::via::Skip;
2  
3 #use 5.008004;
4 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use Data::Dumper;
7  
8 require Exporter;
9  
10 our $VERSION = '0.06';
11 24 ▶use constant DEFAULTS => ( start => undef ,
Subroutine BEGIN: called CC=1 SCAR=3.5
12 end => undef ,
13 maxlines => undef ,
14 skippatterns => undef ,
15 skipblanklines => 0 ,
16 skipcomments => 0 ,
17 after => 0 ,
18 nread_ => 0 ,
19 nwrite_ => 0 ,
20 n_ => 0 ,
21 0 ▶ bipolar => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
22 0 my $obj = shift;
23 0 ▶ ($_[0]..$_[1]) ? ++$obj->{n_} : ($obj->{n_}=0);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] .. $_[1] ? : 0 0 0
24 0 ▶ ($obj->{n_} > ($obj->{after}||0)) ? return 1 :0;
Branch: 1 branch
BranchTrueFalseTotal
$obj->{'n_'} > ($obj->{'after'} || 0) ? : 0 0 0
Condition0%0/2
$obj->{'after'} || 0
l!l
00
MC/DC0%0/1
$obj->{'after'} || 0
$obj->{'after'}
Truth table0%0/2
A
A= $obj->{'after'}
Aresult
11
00
25 24 }, );
26  
27  
28 0 ▶sub PUSHED {
Subroutine PUSHED: not called CC=7 SCAR=40.3
29 0 my ($class, $mode, $fh) = @_ ;
30 0 ▶ ($mode =~ /^[rwa]$/) or return -1 ;
Branch: 1 branch
BranchTrueFalseTotal
$mode =~ /^[rwa]$/ or return -1 0 0 0
31 my $obj = (defined $ENV{ viaSKIP})
32 0 ▶ ? bless { DEFAULTS, %{$ENV{ viaSKIP}} }
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'viaSKIP'} ? : 0 0 0
33 : bless { DEFAULTS } ;
34 # init stuff
35 0 reset;
36 0 $obj->{qr_} = [compile_patterns( $obj->{skippatterns} ) ];
37 0 ▶ $obj->{skipblanklines} and ($obj->{qr_} = [ qr/^\s*$/, @{$obj->{qr_}}]);
Branch: 1 branch
BranchTrueFalseTotal
$obj->{"skipblanklines"} and $obj->{"qr_"} = [qr/^\s*$/, @{$obj->{"qr_"};}] 0 0 0
38 0 ▶ $obj->{skipcomments} and ($obj->{qr_} = [ qr/^\s*#/, @{$obj->{qr_}}]);
Branch: 1 branch
BranchTrueFalseTotal
$obj->{"skipcomments"} and $obj->{"qr_"} = [qr/^\s*#/, @{$obj->{"qr_"};}] 0 0 0
39 0 ($obj->{bipolar})->( $obj, 0, 1 );
40 (defined $obj->{start}) ? ($obj->{start} = qr/\s*$obj->{start}\s*/)
41 0 ▶ : ($obj->{start} = qr/^/ );
Branch: 1 branch
BranchTrueFalseTotal
defined $obj->{'start'} ? : 0 0 0
42 (defined $obj->{ end }) ? ($obj->{ end } = qr/\s*$obj->{ end }\s*/)
43 0 ▶ : ($obj->{ end } = qr/^.\A/ );
Branch: 1 branch
BranchTrueFalseTotal
defined $obj->{'end'} ? : 0 0 0
44 0 $obj;
45 }
46  
47 0 ▶sub compile_patterns {
Subroutine compile_patterns: not called CC=3 SCAR=24.8
48 0 my $pats = shift;
49 0 ▶ return unless $pats;
Branch: 1 branch
BranchTrueFalseTotal
unless $pats 0 0 0
50 0 ▶ return qr/$pats/ unless ref $pats;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pats 0 0 0
51 0 map {qr/$_/} @$pats;
52 }
53  
54  
55  
56 sub FILL {
57 my ($obj, $fh) = @_ ;
58  
59 # stop output if maxlines will be exceeded
60 (defined $obj->{maxlines}) &&
61 ($obj->{nread_} >= $obj->{maxlines}) && return;
62 local $_ = <$fh>;
63 return undef unless (defined $_);
64 my ($s, $e) = ( $obj->{start} , $obj->{end} );
65 until ( pattern_check( $obj , $_ ) &&
66 ($obj->{bipolar})->( $obj, scalar (?$s?), scalar (/$e/) )
67 ){
68 $_ = <$fh>;
69 $. = $obj->{nread_};
70 return undef unless (defined $_);
71 }
72 # update stats
73 $. = ++ $obj->{nread_};
74 $_;
75 }
76  
77  
78 sub pattern_check {
79 # return FALSE if line should be ignored
80 my ($obj, $line) = @_ ;
81 return 1 unless @{$obj->{qr_}};
82 for (@{$obj->{qr_}} ) {
83 return 0 if $line =~ $_ ;
84 }
85 1;
86 }
87  
88  
89 sub WRITE {
90 my ($obj, $buf, $fh) = @_ ;
91 local $_ = $buf;
92  
93 return 0 if (defined $obj->{maxlines}) &&
94 ($obj->{nwrite_} >= $obj->{maxlines});
95 return 0 unless pattern_check( $obj , $_ );
96 my $s = ?$obj->{start}? ;
97 my $e = /$obj->{end}/ ;
98 #print qq (write: "$_"\n);
99 return 0 unless ($obj->{bipolar})->( $obj , $s , $e );
100 printf $fh "%s", $buf;
101 ++ $obj->{nwrite_};
102 length ;
103 }
104  
105 1;
106 __END__
↑ Summary