TextMode/Format.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 83.3% 5 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 2 / 2 totaltotal 88.1% 74 / 84 CC 6 SCAR 8.2
CC
6
Cov
90%
_xs_or_not
5.7
read
2.0
BEGIN
1.0
CRAP 2.3
« TextMode/Writer.pm ↑ Summary TextMode.pm »
1 package Image::TextMode::Format;
2  
3 29 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use Types::Standard qw( Object HashRef InstanceOf );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 ▶use Image::TextMode::Font::8x16;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use Image::TextMode::Palette::VGA;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 29 ▶use Image::TextMode::SAUCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Image::TextMode::Format - A base class for text mode file formats
13  
14 =head1 DESCRIPTION
15  
16 This is a base class for all textmode formats. It provides the basic
17 structure for reading and writing, plus provides some defaults for
18 common attributes (e.g. font and palette).
19  
20 =head1 ACCESSORS
21  
22 =over 4
23  
24 =item * reader - an instance of a file reader
25  
26 =item * writer - and instance of a file writer
27  
28 =item * font - a font instance
29  
30 =item * palette - a palette instance
31  
32 =item * sauce - a SAUCE metadata object
33  
34 =item * render_options - default options for use when rasterizing the data
35  
36 =back
37  
38 =cut
39  
40 29 has 'reader' => (
41 is => 'lazy',
42 isa => InstanceOf['Image::TextMode::Reader'],
43 );
44  
45 29 has 'writer' => (
46 is => 'lazy',
47 isa => InstanceOf['Image::TextMode::Writer'],
48 );
49  
50 sub _build_reader {
51 38 ▶ my ( $self ) = @_;
Subroutine _build_reader: called CC=1 SCAR=0.0
52 38 return $self->_xs_or_not( 'Reader' );
53 }
54  
55 sub _build_writer {
56 7 ▶ my ( $self ) = @_;
Subroutine _build_writer: called CC=1 SCAR=0.0
57 7 return $self->_xs_or_not( 'Writer' );
58 }
59  
60 sub _xs_or_not {
61 45 ▶ my ( $class, $type ) = @_;
Subroutine _xs_or_not: called CC=5 SCAR=17.4
62 45 ▶ ( my $name = ( ref $class || $class ) ) =~ s{\bFormat\b}{$type}s;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
4500
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
63  
64 45 ▶ unless ( $ENV{ IMAGE_TEXTMODE_NOXS } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"IMAGE_TEXTMODE_NOXS"}) 20 25 45
65 20 my $xs = $name . '::XS';
66 20 my $result = eval { Module::Runtime::require_module( $xs ); };
67 20 ▶ if ( $result && !$@ ) { return $xs->new; }
Branch: 1 branch
BranchTrueFalseTotal
if ($result and not $@) 0 20 20
Condition33%1/3
$result and not $@
!ll&&!rl&&r
2000
MC/DC0%0/2
$result and not $@
$result not $@
Truth table33%1/3
A and not(B)
A= $resultB= not $@
ABresult
0X0
100
111
68 }
69  
70 45 Module::Runtime::require_module( $name );
71 45 return $name->new;
72 }
73  
74 has 'font' => (
75 is => 'rw',
76 isa => Object,
77 38 ▶ default => sub { Image::TextMode::Font::8x16->new }
Subroutine __ANON__: called CC=1 SCAR=0.0
78 29 );
79  
80 has 'palette' => (
81 is => 'rw',
82 isa => Object,
83 15 ▶ default => sub { Image::TextMode::Palette::VGA->new }
Subroutine __ANON__: called CC=1 SCAR=0.0
84 29 );
85  
86 has 'sauce' => (
87 is => 'rw',
88 isa => Object,
89 39 ▶ default => sub { Image::TextMode::SAUCE->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
90 29 handles => [ qw( author title group has_sauce ) ]
91 );
92  
93 has 'render_options' =>
94 17 ▶ ( is => 'rw', isa => HashRef, default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
95  
96 =head1 METHODS
97  
98 =head2 new( %args )
99  
100 Creates a new instance.
101  
102 =head2 read( $file, \%options )
103  
104 Proxies to the reader's C<read()> method.
105  
106 =cut
107  
108 sub read { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
109 38 ▶ my ( $self, @rest ) = @_;
Subroutine read: called CC=2 SCAR=6.9
Pod documented
110  
111 # Work-around RT#99225 until we switch to proper roles
112 38 ▶ if( $self->isa( 'Image::TextMode::Canvas' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa("Image::TextMode::Canvas")) 34 4 38
113 34 $self->pixeldata;
114 34 $self->width;
115 34 $self->height;
116 }
117  
118 38 $self->reader->read( $self, @rest );
119 }
120  
121 =head2 write( $file, \%options )
122  
123 Proxies to the writer's C<write()> method.
124  
125 =cut
126  
127 sub write { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
128 7 ▶ my ( $self, @rest ) = @_;
Subroutine write: called CC=1 SCAR=0.0
Pod documented
129 7 $self->writer->write( $self, @rest );
130 }
131  
132 =head1 PROXIED METHODS
133  
134 The following methods are proxies to C<sauce>.
135  
136 =over 4
137  
138 =item * author
139  
140 =item * title
141  
142 =item * group
143  
144 =item * has_sauce
145  
146 =back
147  
148 =cut
149  
150 =head1 AUTHOR
151  
152 Brian Cassidy E<lt>bricas@cpan.orgE<gt>
153  
154 =head1 COPYRIGHT AND LICENSE
155  
156 Copyright 2008-2014 by Brian Cassidy
157  
158 This library is free software; you can redistribute it and/or modify
159 it under the same terms as Perl itself.
160  
161 =cut
162  
163 29 1;
« TextMode/Writer.pm ↑ Summary TextMode.pm »