TextMode/Writer.pm

filter: Statementstmt 89.4% 17 / 19 Branchbran 33.3% 2 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 75.7% 25 / 33 CC 5 SCAR 10.5
CC
5
Cov
74%
_get_fh
3.8
write
3.1
BEGIN
1.0
CRAP 2.9
« TextMode/Writer/Tundra.pm ↑ Summary TextMode/Format.pm »
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 ||= {}
l!l
07
MC/DC0%0/1
$options ||= {}
$options
Truth table50%1/2
A
A= $options
Aresult
11
00
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
BranchTrueFalseTotal
if $image->has_sauce 0 7 7
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
BranchTrueFalseTotal
unless (ref $fh) 0 7 7
42 0 undef $fh;
43 0 ▶ open $fh, '>', $file ## no critic (InputOutput::RequireBriefOpen)
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $file or croak("Unable to open '${file}': $!") 0 0 0
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-2015 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;
« TextMode/Writer/Tundra.pm ↑ Summary TextMode/Format.pm »