blib/lib/Locale/Maketext/Lexicon/Slurp.pm

filter: Statementstmt 95.5% 65 / 68 Branchbran 82.1% 23 / 28 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 90.3% 112 / 124 CC 19 SCAR 23.2
CC
19
Cov
90%
get_files
16.5
read_file
3.1
parse
2.0
CRAP 10.1
↑ Summary
1 package Locale::Maketext::Lexicon::Slurp;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = "0.01";
10 2 our $AUTHORITY = 'NUFFIN';
11  
12 11 ▶sub read_file {
Subroutine read_file: called CC=3 SCAR=11.2
Pod documented
13 11 my ( $self, %args ) = @_;
14  
15 11 local $/;
16  
17 11 my $file = $args{path};
18  
19 11 ▶ open my $fh, "<", $file or die "open($file): $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "open($file): $!" 11 0 11
20  
21 11 ▶ binmode $fh, $args{binmode} if exists $args{binmode};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"binmode"} 0 11 11
22  
23 11 scalar(<$fh>);
24 }
25  
26 2 ▶sub readdir {
Subroutine readdir: called CC=1 SCAR=0.0
Pod documented
27 2 my ( $self, $dir ) = @_;
28 2 grep { -f $_ } $dir->children;
29 }
30  
31 9 ▶sub get_files {
Subroutine get_files: called CC=16 SCAR=28.0
Pod documented
32 9 my ( $self, $args ) = @_;
33  
34 9 my @files;
35 9 ▶ my $dir = $args->{dir} && -d $args->{dir} ? Path::Class::dir($args->{dir}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args->{'dir'} && -d $args->{'dir'} ? : 5 4 9
Condition100%3/3
$args->{"dir"} and -d $args->{"dir"}
!ll&&!rl&&r
135
MC/DC100%2/2
$args->{"dir"} and -d $args->{"dir"}
$args->{"dir"} -d $args->{"dir"}
Truth table100%3/3
A and B
A= $args->{"dir"}B= -d $args->{"dir"}
ABresult
0X0
100
111
36  
37 9 ▶ if ( my $files = $args->{files} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $files = $args->{'files'}) { } 4 5 9
elsif ($dir) { } 2 3 5
elsif ($args->{'dir'}) { } 3 0 3
38 4 ▶ if ( $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 3 1 4
39 3 ▶ if ( (ref($files)||'') ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $files || '') ne 'ARRAY') { } 2 1 3
Condition100%2/2
ref $files || ''
l!l
21
MC/DC100%1/1
ref $files || ''
ref $files
Truth table100%2/2
A
A= ref $files
Aresult
11
00
40 2 ▶ @files = map { Path::Class::file($_) } glob( $dir->file($files)->stringify );
Subroutine BEGIN: called CC=1 SCAR=0.0
41 } else {
42 1 @files = map { $dir->file($_) } @$files;
43 }
44 } else {
45 1 ▶ if ( (ref($files)||'') ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $files || '') ne 'ARRAY') { } 0 1 1
Condition50%1/2
ref $files || ''
l!l
10
MC/DC0%0/1
ref $files || ''
ref $files
Truth table50%1/2
A
A= ref $files
Aresult
11
00
46 0 @files = map { Path::Class::file($_) } glob($files);
47 } else {
48 1 @files = @$files;
49 }
50 }
51 } elsif ( $dir ) {
52 2 ▶ my $readdir = $args->{readdir} || "readdir";
Condition50%1/2
$args->{'readdir'} || 'readdir'
l!l
02
MC/DC0%0/1
$args->{'readdir'} || 'readdir'
$args->{'readdir'}
Truth table50%1/2
A
A= $args->{'readdir'}
Aresult
11
00
53 2 @files = $self->$readdir( $dir );
54 } elsif ( $args->{dir} ) { # not a directory, special case for 1 arg form
55 3 @files = map { Path::Class::file($_) } glob($args->{dir});
56 }
57  
58 9 ▶ if ( my $re = $args->{regex} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $re = $args->{"regex"}) 2 7 9
59 2 @files = grep { $_ =~ $re } @files;
60 }
61  
62 9 ▶ if ( my $filter = $args->{filter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $filter = $args->{"filter"}) 1 8 9
63 1 @files = grep { $self->$filter( $_ ) } @files;
64 }
65  
66 9 ▶ if ( @files ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) 9 0 9
67 9 ▶ if ( $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 5 4 9
68 5 my $dir_obj = Path::Class::dir($dir);
69 5 return { map { Path::Class::file($_)->relative( $dir_obj )->stringify => "$_" } @files },
70 } else {
71 4 return { map { File::Basename::basename($_) => "$_" } @files };
72 }
73 }
74  
75 0 die "No files specified";
76 }
77  
78 9 ▶sub parse {
Subroutine parse: called CC=2 SCAR=6.9
Pod documented
79 9 my ( $self, @args ) = @_;
80  
81 9 ▶ unshift @args, "dir" if @args % 2 == 1; # work in Lexicon's * mode
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 == 1 8 1 9
82  
83 9 my $args = { @args };
84  
85 9 my $files = $self->get_files( $args );
86  
87 return {
88 map {
89 9 my $name = $_;
90 13 my $path = $files->{$name};
91 11 ▶ $name => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
92 11 return $self->read_file(
93 %$args,
94 path => $path,
95 name => $name,
96 args => \@_
97 )
98 }
99 13 } keys %$files
100 };
101 }
102  
103 2 1;
104  
105 __END__
↑ Summary