| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | 1 | ▶ | if (my $charset = $self->{charset}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||