Grep/Root.pm

filter: Statementstmt 43.3% 26 / 60 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 53.3% 8 / 15 Podpod 100% 5 / 5 totaltotal 37.5% 39 / 104 CC 10 SCAR 30.2
CC
10
Cov
32%
_check_variable
56.0
is_arrayref_of_size
20.0
is_integer
2.0
CRAP 20.4
↑ Summary Grep/SearchResult.pm »
1 #############################################################################
2 # $Author: markus $
3 # $Date: 2009-11-12 17:13:23 +0100 (Thu, 12 Nov 2009) $
4 # $Revision: 1844 $
5 #############################################################################
6  
7 package Bio::Grep::Root;
8  
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use version; our $VERSION = qv('0.10.6');
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use base 'Bio::Root::Root';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶sub is_integer {
Subroutine is_integer: not called CC=1 SCAR=6.9
Pod documented
23 0 my ( $self, $variable, $desc ) = @_;
24 0 return $self->_check_variable(
25 variable => $variable,
26 desc => $desc,
27 regex => 'int'
28 );
29 }
30  
31 0 ▶sub is_word {
Subroutine is_word: not called CC=1 SCAR=6.9
Pod documented
32 0 my ( $self, $variable, $desc ) = @_;
33 0 return $self->_check_variable(
34 variable => $variable,
35 desc => $desc,
36 regex => 'word'
37 );
38 }
39  
40 0 ▶sub is_path {
Subroutine is_path: not called CC=1 SCAR=6.9
Pod documented
41 0 my ( $self, $variable, $desc ) = @_;
42 0 return $self->_check_variable(
43 variable => $variable,
44 desc => $desc,
45 regex => 'path'
46 );
47 }
48  
49 0 ▶sub is_sentence {
Subroutine is_sentence: not called CC=1 SCAR=6.9
Pod documented
50 0 my ( $self, $variable, $desc ) = @_;
51 0 return $self->_check_variable(
52 variable => $variable,
53 desc => $desc,
54 regex => 'sentence'
55 );
56 }
57  
58 0 ▶sub is_arrayref_of_size {
Subroutine is_arrayref_of_size: not called CC=4 SCAR=30.0
Pod documented
59 0 my ( $self, $a_ref, $size ) = @_;
60 0 my $reftype = reftype $a_ref;
61 0 ▶ if ( !defined $reftype || $reftype ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $reftype or $reftype ne "ARRAY") 0 0 0
Condition0%0/3
not defined $reftype or $reftype ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $reftype or $reftype ne "ARRAY"
not defined $reftype $reftype ne "ARRAY"
Truth table0%0/3
not(A) or B
A= not defined $reftypeB= $reftype ne "ARRAY"
ABresult
1X1
011
000
62 0 $self->throw(
63 -class => 'Bio::Root::BadParameter',
64 -text => 'Argument is not an array reference',
65 -value => $reftype
66 );
67 }
68 0 ▶ if ( scalar @{$a_ref} < $size ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$a_ref;} < $size) 0 0 0
69 $self->throw(
70 -class => 'Bio::Root::BadParameter',
71 -text => 'Size of argument is too small.',
72 0 -value => scalar @{$a_ref} . " vs. $size"
73 );
74 }
75 0 return 1;
76 }
77  
78 ###############################################################################
79 # Usage : $self->_check_variable(%args)
80 # Purpose : make perl -T happy: get only "secure" symbols for system()
81 # Returns : the specified variable if it is ok
82 # Parameters : ( variable => $v, regex => 'int', desc => $desc )
83 # Throws : Bio::Root::BadParameter if variable is not ok
84 # Comments : if variable is undef, then return value is undef
85 # See also : http://gunther.web66.com/FAQS/taintmode.html
86  
87 0 ▶sub _check_variable {
Subroutine _check_variable: not called CC=7 SCAR=40.3
88 0 my ( $self, %args ) = @_;
89  
90 0 ▶ if ( !%args || !defined $args{regex} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%args and defined $args{"regex"}) 0 0 0
Condition0%0/3
%args and defined $args{"regex"}
!ll&&!rl&&r
000
MC/DC0%0/2
%args and defined $args{"regex"}
%args defined $args{"regex"}
Truth table0%0/3
A and B
A= %argsB= defined $args{"regex"}
ABresult
0X0
100
111
91 0 $self->throw(
92 -class => 'Bio::Root::BadParameter',
93 -text => 'Missing arguments: require hash with keys "regex"'
94 . '"variable" and optional "desc"',
95 );
96 }
97 0 ▶ return if !defined $args{variable};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"variable"} 0 0 0
98  
99 0 ▶ if ( !defined $args{desc} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"desc"}) 0 0 0
100 0 $args{desc} = 'Variable';
101 }
102 0 my $value;
103  
104 0 my %regexes = (
105 'int' => qr{ ( \A \d+ \z ) }xms,
106 'word' => qr{ ( \A [\w.\-]+ \z ) }xms,
107 'path' => qr{ ( \A [\w.\-/\\: ]+ \z ) }xms,
108 'sentence' => qr{ \A ([\w.\-/|:(),;]+) }xms,
109 );
110  
111 0 ▶ if ( defined $regexes{ $args{regex} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $regexes{$args{'regex'}}) { } 0 0 0
112 0 ($value) = $args{variable} =~ $regexes{ $args{regex} };
113 }
114 else {
115 $self->throw(
116 -class => 'Bio::Root::BadParameter',
117 -text => 'Unknown regex.',
118 -value => $args{regex}
119 0 );
120 }
121  
122 0 ▶ if ( !defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
123 $self->throw(
124 -class => 'Bio::Root::BadParameter',
125 -text => $args{desc} . ' looks not valid.',
126 -value => $args{variable}
127 0 );
128 }
129 0 return $value;
130 }
131  
132 0 ▶sub _cannot_print {
Subroutine _cannot_print: not called CC=1 SCAR=6.9
133 0 my ( $self, $filename ) = @_;
134 0 $self->throw(
135 -class => 'Bio::Root::IOException',
136 -text => 'Cannot write to file',
137 -value => $filename
138 );
139 0 return;
140 }
141  
142 2 1; # Magic true value required at end of module
143 __END__
↑ Summary Grep/SearchResult.pm »