| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Image::TextMode::Reader; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 19 |  |  | 19 |  | 8795 | use Moo; | 
|  | 19 |  |  |  |  | 32 |  | 
|  | 19 |  |  |  |  | 130 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 19 |  |  | 19 |  | 5284 | use Carp 'croak'; | 
|  | 19 |  |  |  |  | 34 |  | 
|  | 19 |  |  |  |  | 5086 |  | 
| 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 |  |  | 38 | 1 | 7907 | my ( $self, $image, $fh, $options ) = @_; | 
| 30 | 38 |  | 50 |  |  | 286 | $options ||= {}; | 
| 31 | 38 |  |  |  |  | 105 | $fh = _get_fh( $fh ); | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 38 |  |  |  |  | 904 | $image->sauce->read( $fh ); | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 38 |  |  |  |  | 869 | seek( $fh, 0, 2 ); | 
| 36 | 38 |  |  |  |  | 104 | $options->{ filesize } = tell $fh; | 
| 37 | 38 |  |  |  |  | 79 | seek( $fh, 0, 0 ); | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 38 | 100 |  |  |  | 541 | if( $image->has_sauce ) { | 
| 40 | 1 | 50 |  |  |  | 49 | if ( !$options->{ width } ) { | 
| 41 | 1 |  |  |  |  | 17 | $options->{ width } = $image->sauce->tinfo1; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 1 |  |  |  |  | 57 | $options->{ filesize } -= $image->sauce->record_size; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 38 |  |  |  |  | 19604 | seek( $fh, 0, 0 ); | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 38 |  |  |  |  | 197 | $self->_read( $image, $fh, $options ); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub _get_fh { | 
| 53 | 38 |  |  | 38 |  | 68 | my ( $file ) = @_; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 38 |  |  |  |  | 71 | my $fh = $file; | 
| 56 | 38 | 100 |  |  |  | 121 | if ( !ref $fh ) { | 
| 57 | 32 |  |  |  |  | 52 | undef $fh; | 
| 58 | 32 | 50 |  |  |  | 1525 | open $fh, '<', $file    ## no critic (InputOutput::RequireBriefOpen) | 
| 59 |  |  |  |  |  |  | or croak "Unable to open '$file': $!"; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 38 |  |  |  |  | 114 | binmode( $fh ); | 
| 63 | 38 |  |  |  |  | 104 | return $fh; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =head1 AUTHOR | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | Brian Cassidy Ebricas@cpan.orgE | 
| 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 |  |  |  |  |  |  | 1; |