Scigen.pm

filter: Statementstmt 96.1% 50 / 52 Branchbran 50.0% 7 / 14 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 86.4% 70 / 81 CC 9 SCAR 12.3
CC
9
Cov
85%
new
6.7
_find
3.5
generate
2.0
CRAP 3.4
« Scigen/scigen.pm ↑ Summary
1 package Text::Scigen;
2  
3 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @ISA = qw(Exporter);
11  
12 # Items to export into callers namespace by default. Note: do not export
13 # names by default without a very good reason. Use EXPORT_OK instead.
14 # Do not simply export all your public functions/methods/constants.
15  
16 # This allows declaration use Text::Scigen ':all';
17 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18 # will save memory.
19 1 our %EXPORT_TAGS = ( 'all' => [ qw(
20
21 ) ] );
22  
23 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
24  
25 1 our @EXPORT = qw(
26
27 );
28  
29 1 our $VERSION = '0.02';
30  
31 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Text::Autoformat;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Text::Scigen::scigen;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 our $DATA_PATH = $INC{'Text/Scigen.pm'};
36 1 $DATA_PATH =~ s/Scigen\.pm$//;
37 1 $DATA_PATH .= "Scigen";
38 1 our $REL_PATH;
39  
40 # Preloaded methods go here.
41  
42 # Autoload methods go after =cut, and are processed by the autosplit program.
43  
44 sub new
45 1 ▶{
Subroutine new: called CC=6 SCAR=19.1
Pod documented
46 1 my( $class, %self ) = @_;
47  
48 1 my $self = bless \%self, $class;
49  
50 Carp::croak( "Missing filename argument" )
51 1 ▶ if !defined $self{filename};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self{"filename"} 0 1 1
52  
53 $self{filename} = "$DATA_PATH/$self{filename}"
54 1 ▶ if $self{filename} !~ /^\//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self{"filename"} =~ m[^/] 1 0 1
55  
56 1 $self{rel_path} = $self{filename};
57 1 $self{rel_path} =~ s/\/[^\/]+$//;
58  
59 1 ▶ $self{debug} ||= 0;
Condition50%1/2
$self{"debug"} ||= 0
l!l
01
MC/DC0%0/1
$self{"debug"} ||= 0
$self{"debug"}
Truth table50%1/2
A
A= $self{"debug"}
Aresult
11
00
60  
61 1 ▶ $self{pretty} = 1 if !defined $self{pretty};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self{"pretty"} 1 0 1
62  
63 1 ▶ if( open(my $fh, "<:utf8", $self{filename}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '<:utf8', $self{'filename'}) { } 1 0 1
64 Text::Scigen::scigen::read_rules (
65 $fh,
66 $self{dat} = {},
67 \$self{RE},
68 $self{debug},
69 1 $self
70 );
71 }
72 else {
73 0 Carp::croak( "Error reading from $self{filename}: $!" );
74 }
75  
76 1 return $self;
77 }
78  
79 sub generate
80 1 ▶{
Subroutine generate: called CC=2 SCAR=7.0
Pod documented
81 1 my( $self, $start ) = @_;
82  
83 1 ▶ $start = [$start] if ref($start) ne "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $start ne "ARRAY" 1 0 1
84  
85 1 return join "\n", map { Text::Scigen::scigen::generate (
86 $self->{dat},
87 $_,
88 $self->{RE},
89 $self->{debug},
90 $self->{pretty}
91 1 ) } @$start;
92 }
93  
94 sub _find
95 1 ▶{
Subroutine _find: called CC=3 SCAR=12.5
96 1 my( $self, $filename ) = @_;
97  
98 1 ▶ return $filename if -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
if -e $filename 0 1 1
99 1 ▶ return "$self->{rel_path}/$filename" if -e "$self->{rel_path}/$filename";
Branch: 1 branch
BranchTrueFalseTotal
if -e qq[$self->{"rel_path"}/$filename] 1 0 1
100  
101 0 die "Can't find $filename\n";
102 }
103  
104 1 1;
105 __END__
« Scigen/scigen.pm ↑ Summary