| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Image::TextMode::Writer; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 7 |  |  | 7 |  | 3305 | use Moo; | 
|  | 7 |  |  |  |  | 11 |  | 
|  | 7 |  |  |  |  | 47 |  | 
| 4 | 7 |  |  | 7 |  | 1772 | use Carp 'croak'; | 
|  | 7 |  |  |  |  | 11 |  | 
|  | 7 |  |  |  |  | 1538 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | =head1 NAME | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | Image::TextMode::Writer - A base class for file writers | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | This module provides some of the basic functionality for all writer classes. | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =head1 METHODS | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =head2 new( %args ) | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | Creates a new instance. | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =head2 write( $image, $file, \%options ) | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | Writes the contents of C<$image> to C<$file> via the subclass's C<_write()> | 
| 23 |  |  |  |  |  |  | method. | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =cut | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub write {    ## no critic (Subroutines::ProhibitBuiltinHomonyms) | 
| 28 | 7 |  |  | 7 | 1 | 641 | my ( $self, $image, $fh, $options ) = @_; | 
| 29 | 7 |  | 50 |  |  | 62 | $options ||= {}; | 
| 30 | 7 |  |  |  |  | 20 | $fh = _get_fh( $fh ); | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 7 |  |  |  |  | 24 | $self->_write( $image, $fh, $options ); | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 7 | 50 |  |  |  | 191 | $image->sauce->write( $fh ) if $image->has_sauce; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub _get_fh { | 
| 38 | 7 |  |  | 7 |  | 13 | my ( $file ) = @_; | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 7 |  |  |  |  | 10 | my $fh = $file; | 
| 41 | 7 | 50 |  |  |  | 35 | if ( !ref $fh ) { | 
| 42 | 0 |  |  |  |  | 0 | undef $fh; | 
| 43 | 0 | 0 |  |  |  | 0 | open $fh, '>', $file    ## no critic (InputOutput::RequireBriefOpen) | 
| 44 |  |  |  |  |  |  | or croak "Unable to open '$file': $!"; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 7 |  |  |  |  | 22 | binmode( $fh ); | 
| 48 | 7 |  |  |  |  | 17 | return $fh; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =head1 AUTHOR | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | Brian Cassidy Ebricas@cpan.orgE | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | Copyright 2008-2014 by Brian Cassidy | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 60 |  |  |  |  |  |  | it under the same terms as Perl itself. | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =cut | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | 1; |