line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Image::TextMode::Format; |
2
|
|
|
|
|
|
|
|
3
|
29
|
|
|
29
|
|
15171
|
use Moo; |
|
29
|
|
|
|
|
12986
|
|
|
29
|
|
|
|
|
158
|
|
4
|
29
|
|
|
29
|
|
12353
|
use Types::Standard qw( Object HashRef InstanceOf ); |
|
29
|
|
|
|
|
317789
|
|
|
29
|
|
|
|
|
238
|
|
5
|
29
|
|
|
29
|
|
17405
|
use Module::Runtime (); |
|
29
|
|
|
|
|
48
|
|
|
29
|
|
|
|
|
451
|
|
6
|
29
|
|
|
29
|
|
15011
|
use Image::TextMode::Font::8x16; |
|
29
|
|
|
|
|
156
|
|
|
29
|
|
|
|
|
1303
|
|
7
|
29
|
|
|
29
|
|
14483
|
use Image::TextMode::Palette::VGA; |
|
29
|
|
|
|
|
86
|
|
|
29
|
|
|
|
|
1090
|
|
8
|
29
|
|
|
29
|
|
13615
|
use Image::TextMode::SAUCE; |
|
29
|
|
|
|
|
81
|
|
|
29
|
|
|
|
|
15492
|
|
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
|
|
|
|
|
|
|
has 'reader' => ( |
41
|
|
|
|
|
|
|
is => 'lazy', |
42
|
|
|
|
|
|
|
isa => InstanceOf['Image::TextMode::Reader'], |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'writer' => ( |
46
|
|
|
|
|
|
|
is => 'lazy', |
47
|
|
|
|
|
|
|
isa => InstanceOf['Image::TextMode::Writer'], |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _build_reader { |
51
|
38
|
|
|
38
|
|
11341
|
my ( $self ) = @_; |
52
|
38
|
|
|
|
|
209
|
return $self->_xs_or_not( 'Reader' ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _build_writer { |
56
|
7
|
|
|
7
|
|
4298
|
my ( $self ) = @_; |
57
|
7
|
|
|
|
|
35
|
return $self->_xs_or_not( 'Writer' ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _xs_or_not { |
61
|
45
|
|
|
45
|
|
92
|
my ( $class, $type ) = @_; |
62
|
45
|
|
33
|
|
|
413
|
( my $name = ( ref $class || $class ) ) =~ s{\bFormat\b}{$type}s; |
63
|
|
|
|
|
|
|
|
64
|
45
|
100
|
|
|
|
254
|
unless ( $ENV{ IMAGE_TEXTMODE_NOXS } ) { |
65
|
20
|
|
|
|
|
58
|
my $xs = $name . '::XS'; |
66
|
20
|
|
|
|
|
31
|
my $result = eval { Module::Runtime::require_module( $xs ); }; |
|
20
|
|
|
|
|
102
|
|
67
|
20
|
50
|
33
|
|
|
5220
|
if ( $result && !$@ ) { return $xs->new; } |
|
0
|
|
|
|
|
0
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
45
|
|
|
|
|
184
|
Module::Runtime::require_module( $name ); |
71
|
45
|
|
|
|
|
1042
|
return $name->new; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
has 'font' => ( |
75
|
|
|
|
|
|
|
is => 'rw', |
76
|
|
|
|
|
|
|
isa => Object, |
77
|
|
|
|
|
|
|
default => sub { Image::TextMode::Font::8x16->new } |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
has 'palette' => ( |
81
|
|
|
|
|
|
|
is => 'rw', |
82
|
|
|
|
|
|
|
isa => Object, |
83
|
|
|
|
|
|
|
default => sub { Image::TextMode::Palette::VGA->new } |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has 'sauce' => ( |
87
|
|
|
|
|
|
|
is => 'rw', |
88
|
|
|
|
|
|
|
isa => Object, |
89
|
|
|
|
|
|
|
default => sub { Image::TextMode::SAUCE->new }, |
90
|
|
|
|
|
|
|
handles => [ qw( author title group has_sauce ) ] |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
has 'render_options' => |
94
|
|
|
|
|
|
|
( is => 'rw', isa => HashRef, default => sub { {} } ); |
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 method. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub read { ## no critic (Subroutines::ProhibitBuiltinHomonyms) |
109
|
38
|
|
|
38
|
1
|
2449
|
my ( $self, @rest ) = @_; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Work-around RT#99225 until we switch to proper roles |
112
|
38
|
100
|
|
|
|
294
|
if( $self->isa( 'Image::TextMode::Canvas' ) ) { |
113
|
34
|
|
|
|
|
453
|
$self->pixeldata; |
114
|
34
|
|
|
|
|
1090
|
$self->width; |
115
|
34
|
|
|
|
|
15206
|
$self->height; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
38
|
|
|
|
|
15612
|
$self->reader->read( $self, @rest ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 write( $file, \%options ) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Proxies to the writer's C method. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub write { ## no critic (Subroutines::ProhibitBuiltinHomonyms) |
128
|
7
|
|
|
7
|
1
|
12106
|
my ( $self, @rest ) = @_; |
129
|
7
|
|
|
|
|
66
|
$self->writer->write( $self, @rest ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 PROXIED METHODS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The following methods are proxies to C. |
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 Ebricas@cpan.orgE |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Copyright 2008-2015 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
|
|
|
|
|
|
|
1; |