| 1 | package Image::TextMode::Writer; | ||||||||||||
| 2 | |||||||||||||
| 3 | 7 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 7 | ▶ | use Carp 'croak'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 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 | ▶ | my ( $self, $image, $fh, $options ) = @_; | ||||||||||
|
Subroutine
write: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||
| 29 | 7 | ▶ | $options ||= {}; | ||||||||||
|
Condition50%1/2
$options ||= {}
MC/DC0%0/1
$options ||= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||
| 30 | 7 | $fh = _get_fh( $fh ); | |||||||||||
| 31 | |||||||||||||
| 32 | 7 | $self->_write( $image, $fh, $options ); | |||||||||||
| 33 | |||||||||||||
| 34 | 7 | ▶ | $image->sauce->write( $fh ) if $image->has_sauce; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | sub _get_fh { | ||||||||||||
| 38 | 7 | ▶ | my ( $file ) = @_; | ||||||||||
|
Subroutine
_get_fh: called CC=3 SCAR=13.5
| |||||||||||||
| 39 | |||||||||||||
| 40 | 7 | my $fh = $file; | |||||||||||
| 41 | 7 | ▶ | if ( !ref $fh ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 0 | undef $fh; | |||||||||||
| 43 | 0 | ▶ | open $fh, '>', $file ## no critic (InputOutput::RequireBriefOpen) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | or croak "Unable to open '$file': $!"; | ||||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 7 | binmode( $fh ); | |||||||||||
| 48 | 7 | return $fh; | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | =head1 AUTHOR | ||||||||||||
| 52 | |||||||||||||
| 53 | Brian Cassidy E<lt>bricas@cpan.orgE<gt> | ||||||||||||
| 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 | 7 | 1; | |||||||||||