blib/lib/Text/APL/Reader.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 94.1% 64 / 68 SCAR 20.8
CC
8
Cov
93%
build
5.0
_build_file_reader
3.0
__ANON__
2.0
CRAP 8.0
« blib/lib/Text/APL/Core.pm ↑ Summary blib/lib/Text/APL/Writer.pm »
1 package Text::APL::Reader;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base 'Text::APL::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub build {
9 24 ▶ my $self = shift;
Subroutine build: called CC=5 SCAR=16.2
Pod documented
10 24 my ($input) = @_;
11  
12 24 my $reader;
13  
14 24 ▶ if (!ref $input) {
Branch: 4 branches
BranchTrueFalseTotal
if (not ref $input) { } 1 23 24
elsif (ref $input eq 'GLOB') { } 1 22 23
elsif (ref $input eq 'SCALAR') { } 21 1 22
elsif (ref $input eq 'CODE') { } 1 0 1
15 1 $reader = $self->_build_file_reader($input);
16 }
17 elsif (ref $input eq 'GLOB') {
18 1 $reader = $self->_build_file_handle_reader($input);
19 }
20 elsif (ref $input eq 'SCALAR') {
21 21 $reader = $self->_build_string_reader($input);
22 }
23 elsif (ref $input eq 'CODE') {
24 1 $reader = $input;
25 }
26 else {
27 0 die 'Do not know how to read';
28 }
29  
30 24 return $reader;
31 }
32  
33 sub _build_file_reader {
34 1 ▶ my $self = shift;
Subroutine _build_file_reader: called CC=3 SCAR=11.1
35 1 my ($input) = @_;
36  
37 1 ▶ open my $fh, '<', $input or die "Can't open '$input': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $input or die "Can't open '${input}': $!" 0 1 1
38  
39 1 ▶ if (my $charset = $self->{charset}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $charset = $self->{"charset"}) 1 0 1
40 1 ▶ binmode $fh, ":encoding($charset)";
Subroutine BEGIN: called CC=1 SCAR=0.0
41 }
42  
43 1 return $self->_build_file_handle_reader($fh);
44 }
45  
46 sub _build_file_handle_reader {
47 2 ▶ my $self = shift;
Subroutine _build_file_handle_reader: called CC=1 SCAR=0.0
48 2 my ($input) = @_;
49  
50 sub {
51 2 ▶ my ($cb) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
52 2 ▶ while (defined(my $line = <$input>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $input)) 2 2 4
53 2 $cb->($line);
54 }
55 2 $cb->();
56 2 };
57 }
58  
59 sub _build_string_reader {
60 21 ▶ my $self = shift;
Subroutine _build_string_reader: called CC=1 SCAR=0.0
61 21 my ($input) = @_;
62  
63 sub {
64 21 ▶ my ($cb) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
65  
66 21 $cb->(${$input});
67 21 $cb->();
68 21 };
69 }
70  
71 3 1;
72 __END__
« blib/lib/Text/APL/Core.pm ↑ Summary blib/lib/Text/APL/Writer.pm »