line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EPL2::Command::A; |
2
|
|
|
|
|
|
|
# ABSTRACT: A Command (ASCII Text) |
3
|
|
|
|
|
|
|
$EPL2::Command::A::VERSION = '0.001'; |
4
|
3
|
|
|
3
|
|
295118
|
use 5.010; |
|
3
|
|
|
|
|
7
|
|
5
|
3
|
|
|
3
|
|
496
|
use Moose; |
|
3
|
|
|
|
|
282834
|
|
|
3
|
|
|
|
|
14
|
|
6
|
3
|
|
|
3
|
|
13299
|
use MooseX::Method::Signatures; |
|
3
|
|
|
|
|
1712475
|
|
|
3
|
|
|
|
|
14
|
|
7
|
3
|
|
|
3
|
|
374
|
use namespace::autoclean; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
21
|
|
8
|
3
|
|
|
3
|
|
991
|
use EPL2::Types ( 'Natural', 'Rotation', 'Mult', 'Reverse', 'Font', 'Text' ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
13
|
|
9
|
3
|
|
|
3
|
|
8207
|
use Text::Wrap::Smart::XS 'exact_wrap'; |
|
3
|
|
|
|
|
13088
|
|
|
3
|
|
|
|
|
1033
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'EPL2::Command'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#Public Attributes |
14
|
|
|
|
|
|
|
has h_pos => ( is => 'rw', isa => Natural, default => 0 ); |
15
|
|
|
|
|
|
|
has v_pos => ( is => 'rw', isa => Natural, default => 0 ); |
16
|
|
|
|
|
|
|
has rotation => ( is => 'rw', isa => Rotation, default => 0 ); |
17
|
|
|
|
|
|
|
has font => ( is => 'rw', isa => Font, default => 1 ); |
18
|
|
|
|
|
|
|
has h_mult => ( is => 'rw', isa => Mult, default => 1 ); |
19
|
|
|
|
|
|
|
has v_mult => ( is => 'rw', isa => Mult, default => 1 ); |
20
|
|
|
|
|
|
|
has 'reverse' => ( is => 'rw', isa => Reverse, default => 'N' ); |
21
|
|
|
|
|
|
|
has text => ( is => 'ro', isa => Text, required => 1 ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#Private Attributes |
24
|
|
|
|
|
|
|
has width => ( is => 'ro', init_arg => undef, builder => '_b_width', lazy => 1 ); |
25
|
|
|
|
|
|
|
has height => ( is => 'ro', init_arg => undef, builder => '_b_height', lazy => 1 ); |
26
|
|
|
|
|
|
|
has fonts => ( is => 'ro', init_arg => undef, builder => '_b_fonts' ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#Builders |
29
|
|
|
|
|
|
|
sub _b_width { |
30
|
3
|
|
|
3
|
|
4
|
my ($self) = @_; |
31
|
3
|
|
|
|
|
89
|
my $txt = $self->text; |
32
|
3
|
|
|
|
|
8
|
$txt =~ s/^"//; |
33
|
3
|
|
|
|
|
7
|
$txt =~ s/"$//; |
34
|
3
|
50
|
33
|
|
|
63
|
if ( !$self->rotation || $self->rotation == 2 ) { |
35
|
3
|
|
|
|
|
4
|
return $self->_b_fonts->{ $self->font }{width} * length( $txt ); |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
0
|
return $self->_b_fonts->{$self->font}{height}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
sub _b_height { |
40
|
3
|
|
|
3
|
|
2
|
my ($self) = @_; |
41
|
3
|
50
|
33
|
|
|
60
|
if ( !$self->rotation || $self->rotation == 2 ) { |
42
|
3
|
|
|
|
|
5
|
return $self->_b_fonts->{$self->font}{height}; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
0
|
return $self->_b_fonts->{ $self->font }{width} * length( $self->text ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
sub _b_fonts { |
47
|
|
|
|
|
|
|
return { |
48
|
|
|
|
|
|
|
( |
49
|
10
|
|
|
10
|
|
238
|
1 => { width => 8 + 2, height => 12 + 2 }, |
50
|
|
|
|
|
|
|
2 => { width => 10 + 2, height => 16 + 2 }, |
51
|
|
|
|
|
|
|
3 => { width => 12 + 2, height => 20 + 2 }, |
52
|
|
|
|
|
|
|
4 => { width => 14 + 2, height => 24 + 2 }, |
53
|
|
|
|
|
|
|
5 => { width => 32 + 2, height => 48 + 2 } |
54
|
|
|
|
|
|
|
) |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#Methods |
59
|
3
|
|
|
3
|
|
548021
|
method string ( Str :$delimiter = "\n" ) { |
60
|
|
|
|
|
|
|
sprintf 'A%d,%d,%d,%d,%d,%d,%s,%s%s', |
61
|
|
|
|
|
|
|
$self->h_pos, $self->v_pos, $self->rotation, $self->font, |
62
|
|
|
|
|
|
|
$self->h_mult, $self->v_mult, $self->reverse, $self->text, |
63
|
|
|
|
|
|
|
$delimiter; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub multi_lines { |
67
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
68
|
1
|
|
|
|
|
3
|
my %args = @_; |
69
|
1
|
|
|
|
|
1
|
my ( @A, $txt ); |
70
|
1
|
|
|
|
|
2
|
$txt = $args{text}; |
71
|
1
|
|
|
|
|
7
|
$txt =~ s/( \r | \n | \t )//mxg; |
72
|
1
|
|
|
|
|
1
|
$txt =~ s/^"//; |
73
|
1
|
|
|
|
|
2
|
$txt =~ s/"$//; |
74
|
1
|
|
|
|
|
4
|
my @chunks = exact_wrap($txt, $args{length}); |
75
|
1
|
|
|
|
|
99
|
delete $args{text}; |
76
|
1
|
|
|
|
|
2
|
delete $args{length}; |
77
|
1
|
|
|
|
|
2
|
for my $chunk ( @chunks ) { |
78
|
2
|
|
|
|
|
48
|
my $A = $class->new( %args, text => qq{"$chunk"} ); |
79
|
2
|
50
|
33
|
|
|
7
|
if ( !$args{rotation} || $args{rotation} == 2 ) { |
80
|
2
|
|
|
|
|
57
|
$args{v_pos} = $A->v_pos + $A->height; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
0
|
$args{h_pos} = $A->h_pos + $A->width; |
84
|
|
|
|
|
|
|
} |
85
|
2
|
|
|
|
|
3
|
push @A, $A |
86
|
|
|
|
|
|
|
} |
87
|
1
|
|
|
|
|
6
|
return @A; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=pod |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=encoding UTF-8 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 NAME |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
EPL2::Command::A - A Command (ASCII Text) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 VERSION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
version 0.001 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SYNOPSIS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $A = EPL2::Command::A->new( text => q{"Ascii TEXT"} ); |
111
|
|
|
|
|
|
|
say $A->string; |
112
|
|
|
|
|
|
|
my $long_text = 'i can haz cheezburger' x 25; |
113
|
|
|
|
|
|
|
my @bunch = EPL2::Command::A->multi_lines( h_pos => 50, text => $long_text, length => 21 ); |
114
|
|
|
|
|
|
|
say $_->string foreach( @bunch ); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 text ( Text required ) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Text used to create Ascii Text. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 h_pos ( Natural default = 0 ) |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Horizontal Position in dots. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 v_pos ( Natural default = 0 ) |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Vertical Position in dots. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 rotation ( Rotation default = 0 ) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Rotation of Text. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 font ( Font default = 1 ) |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Font Type of Text. Valid font types are [ 1-5 ] |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 h_mult ( Mult default = 1 ) |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Horizontal Multiplier. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 v_mult ( Mult default = 1 ) |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Vertical Multiplier. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 reverse ( Reverse default = 'N' ) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Reverse black and white print. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 width ( private ) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Return width of the text in dots. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 height ( private ) |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Returns height of the text in dots. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 fonts ( private ) |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Return Hashref describing valid fonts. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 METHODS |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 multi_lines |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
params: ( text => 'Stuff to chop up and print muli lines', length => 5 ) |
167
|
|
|
|
|
|
|
text - required |
168
|
|
|
|
|
|
|
length - required ( number of chars per line ) |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Return an array of EPL2::Command::A objects based on text and length. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 string |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
param: ( delimiter => "\n" ) |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Return an EPL2 formatted string used for describing a Ascii text. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SEE ALSO |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L<EPL2> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L<EPL2::Types> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 AUTHOR |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Ted Katseres <tedkat@cpan.org> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Ted Katseres. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
193
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |