| 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 ||= {}
MC/DC0%0/1
$options ||= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||
| 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
| |||||||||||||
| 40 | 1 | ▶ | if ( !$options->{ width } ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 57 | 32 | undef $fh; | |||||||||||
| 58 | 32 | ▶ | open $fh, '<', $file ## no critic (InputOutput::RequireBriefOpen) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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-2015 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; | |||||||||||