| 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
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 11 | ▶ | binmode $fh, $args{binmode} if exists $args{binmode}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$args->{"dir"} and -d $args->{"dir"}
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"}
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 9 | ▶ | if ( my $files = $args->{files} ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 38 | 4 | ▶ | if ( $dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 3 | ▶ | if ( (ref($files)||'') ne 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $files || ''
MC/DC100%1/1
ref $files || ''
ref $files
Truth table100%2/2
A
A= ref $files
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
ref $files || ''
MC/DC0%0/1
ref $files || ''
ref $files
Truth table50%1/2
A
A= ref $files
| |||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$args->{'readdir'} || 'readdir'
$args->{'readdir'}
Truth table50%1/2
A
A= $args->{'readdir'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 59 | 2 | @files = grep { $_ =~ $re } @files; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 9 | ▶ | if ( my $filter = $args->{filter} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 1 | @files = grep { $self->$filter( $_ ) } @files; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 9 | ▶ | if ( @files ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 9 | ▶ | if ( $dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||