TextMode/Reader.pm

filter: Statementstmt 100% 27 / 27 Branchbran 75.0% 6 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 90.7% 39 / 43 CC 6 SCAR 11.0
CC
6
Cov
92%
read
4.0
_get_fh
3.0
BEGIN
1.0
CRAP 3.0
« TextMode/Reader/ANSIMation.pm ↑ Summary TextMode/Writer/Tundra.pm »
1 package Image::TextMode::Reader;
2  
3 19 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 19 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Image::TextMode::Reader - A base class for file readers
10  
11 =head1 DESCRIPTION
12  
13 This module provides some of the basic functionality for all reader classes.
14  
15 =head1 METHODS
16  
17 =head2 new( %args )
18  
19 Creates a new instance.
20  
21 =head2 read( $image, $file, \%options )
22  
23 Reads the contents of C<$file> into C<$image> via the subclass's C<_read()>
24 method.
25  
26 =cut
27  
28 sub read { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
29 38 ▶ my ( $self, $image, $fh, $options ) = @_;
Subroutine read: called CC=4 SCAR=13.9
Pod documented
30 38 ▶ $options ||= {};
Condition50%1/2
$options ||= {}
l!l
038
MC/DC0%0/1
$options ||= {}
$options
Truth table50%1/2
A
A= $options
Aresult
11
00
31 38 $fh = _get_fh( $fh );
32  
33 38 $image->sauce->read( $fh );
34  
35 38 seek( $fh, 0, 2 );
36 38 $options->{ filesize } = tell $fh;
37 38 seek( $fh, 0, 0 );
38  
39 38 ▶ if( $image->has_sauce ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($image->has_sauce) 1 37 38
40 1 ▶ if ( !$options->{ width } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options->{"width"}) 1 0 1
41 1 $options->{ width } = $image->sauce->tinfo1;
42 }
43  
44 1 $options->{ filesize } -= $image->sauce->record_size;
45 }
46  
47 38 seek( $fh, 0, 0 );
48  
49 38 $self->_read( $image, $fh, $options );
50 }
51  
52 sub _get_fh {
53 38 ▶ my ( $file ) = @_;
Subroutine _get_fh: called CC=3 SCAR=11.0
54  
55 38 my $fh = $file;
56 38 ▶ if ( !ref $fh ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fh) 32 6 38
57 32 undef $fh;
58 32 ▶ open $fh, '<', $file ## no critic (InputOutput::RequireBriefOpen)
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $file or croak("Unable to open '${file}': $!") 0 32 32
59 or croak "Unable to open '$file': $!";
60 }
61  
62 38 binmode( $fh );
63 38 return $fh;
64 }
65  
66 =head1 AUTHOR
67  
68 Brian Cassidy E<lt>bricas@cpan.orgE<gt>
69  
70 =head1 COPYRIGHT AND LICENSE
71  
72 Copyright 2008-2014 by Brian Cassidy
73  
74 This library is free software; you can redistribute it and/or modify
75 it under the same terms as Perl itself.
76  
77 =cut
78  
79 19 1;
« TextMode/Reader/ANSIMation.pm ↑ Summary TextMode/Writer/Tundra.pm »