Linemode.pm

filter: Statementstmt 54.2% 19 / 35 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 6 totaltotal 49.0% 25 / 51 CC 1 SCAR 3.4
CC
1
Cov
54%
create_normal_code
2.0
__ANON__
2.0
create_escape_code
2.0
CRAP 1.4
« Linemode/Generated.pm ↑ Summary
1 # Protocol::Star::Linemode - Generates a formatted byte string for Star POS printers
2 # Copyright (c) 2013 Peter Stuifzand
3 # Copyright (c) 2013 Other contributors as noted in the AUTHORS file
4 #
5 # Protocol::Star::Linemode is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public License as
7 # published by the Free Software Foundation; either version 3 of the License,
8 # or (at your option) any later version.
9 #
10 # Protocol::Star::Linemode is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Protocol::Star::Linemode;
19 1 our $VERSION = '1.0.0';
20 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 with qw/
22 Protocol::Star::Linemode::Generated
23 /;
24  
25 has _data => (
26 is => 'rw',
27 2 ▶ default => sub { '' },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 1 );
29  
30 2 ▶sub append {
Subroutine append: called CC=1 SCAR=0.0
Pod undocumented
31 2 my ($self, @data) = @_;
32 2 $self->_data($self->_data . (join '', @data));
33 2 return;
34 }
35  
36 2 ▶sub result {
Subroutine result: called CC=1 SCAR=0.0
Pod undocumented
37 2 my $self = shift;
38 2 return $self->_data;
39 }
40  
41 2 ▶sub append_pack {
Subroutine append_pack: called CC=1 SCAR=0.0
Pod undocumented
42 2 my ($self, $format, @args) = @_;
43 2 $self->append(
44 pack($format, @args)
45 );
46 2 return;
47 }
48  
49 0 ▶sub create_normal_code {
Subroutine create_normal_code: not called CC=1 SCAR=6.9
Pod undocumented
50 0 my ($nargs, @code) = @_;
51  
52 0 my $len = $nargs + scalar @code;
53 0 my $pack_format = 'C' x $len;
54  
55 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 0 my $self = shift;
57 0 my @args = @_;
58 0 $self->append_pack($pack_format, @code, @args);
59 0 return;
60 }
61 0 }
62  
63 0 ▶sub create_escape_code {
Subroutine create_escape_code: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my ($nargs, @code) = @_;
65  
66 0 my $len = 1 + $nargs + scalar @code;
67 0 my $pack_format = 'C' x $len;
68  
69 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 my $self = shift;
71 0 my @args = @_;
72 0 $self->append_pack($pack_format, 0x1B, @code, @args);
73 0 return;
74 }
75 0 }
76  
77 #BEGIN {
78 # no strict 'refs';
79 # my @escape_specs = (
80 # [ 'select_font', 1, 0x1E, 0x46 ],
81 # [ 'select_code_page', 1, 0x1D, 0x74 ],
82 # [ 'set_slash_zero', 1, 0x27 ],
83 # [ 'specify_international_character_set', 1, 0x52 ],
84 # [ 'specify_12_dot_pitch', 0, 0x4D ],
85 # [ 'specify_15_dot_pitch', 0, 0x50 ],
86 # [ 'specify_16_dot_pitch', 0, 0x3A ],
87 # [ 'specify_14_dot_pitch', 0, 0x67 ],
88 # [ 'set_expanded_width_height', 2, 0x69 ],
89 # [ 'set_expanded_width', 1, 0x57 ],
90 # [ 'set_expanded_height', 1, 0x68 ],
91 # [ 'set_double_high', 0, 0x0E ],
92 # [ 'cancel_double_high', 0, 0x14 ],
93 # [ 'set_emphazied_printing', 0, 0x45 ],
94 # [ 'cancel_emphazied_printing', 0, 0x46 ],
95 # [ 'select_underline_mode', 1, 0x2D ],
96 # [ 'select_upperline_mode', 1, 0x5F ],
97 # [ 'select_inverse', 0, 0x34 ],
98 # [ 'cancel_inverse', 0, 0x35 ],
99 # [ 'feed_n_lines', 1, 0x61 ],
100 # [ 'set_page_length', 1, 0x43 ],
101 # [ 'set_page_length_in_24mm_units', 1, 0x43, 0x00 ],
102 # [ 'set_left_margin', 1, 0x6C, ],
103 # [ 'set_right_margin', 1, 0x51, ],
104 # [ 'move_absolute_position', 2, 0x1D, 0x41 ],
105 # [ 'move_relative_position', 2, 0x1D, 0x52 ],
106 # [ 'specify_alignment', 1, 0x1D, 0x61 ],
107 # [ 'align_left', 0, 0x1D, 0x61, 0x00 ],
108 # [ 'align_center', 0, 0x1D, 0x61, 0x01 ],
109 # [ 'align_right', 0, 0x1D, 0x61, 0x02 ],
110 # );
111 #
112 # my @specs = (
113 # [ 'set_double_wide', 1, 0x0E ],
114 # [ 'cancel_double_wide', 1, 0x14 ],
115 # [ 'select_upside_down', 0, 0x0F ],
116 # [ 'cancel_upside_down', 0, 0x12 ],
117 # [ 'lf', 0, 0x0A ],
118 # [ 'cr', 0, 0x13 ],
119 # [ 'form_feed', 0, 0x0C ],
120 # [ 'vertical_tab', 0, 0x0B ],
121 # [ 'horizontal_tab', 0, 0x09 ],
122 # );
123 #
124 # for my $spec (@escape_specs) {
125 # my $name = shift @$spec;
126 # my $nargs = shift @$spec;
127 # *{$name} = create_escape_code($nargs, @$spec);
128 # }
129 # for my $spec (@specs) {
130 # my $name = shift @$spec;
131 # my $nargs = shift @$spec;
132 # *{$name} = create_normal_code($nargs, @$spec);
133 # }
134 #}
135  
136 1 ▶sub text {
Subroutine text: called CC=1 SCAR=0.0
Pod undocumented
137 1 my ($self, $text) = @_;
138 1 $self->append_pack('A*', $text);
139 1 return;
140 }
141  
142 1 1;
143  
144 =head1 NAME
145  
146 Protocol::Star::Linemode - Generates a formatted byte string for Star POS printers
147  
148 =head1 SYNOPSIS
149  
150 use Protocol::Star::Linemode;
151  
152 my $p = Protocol::Star::Linemode->new;
153 $p->set_emphasized_printing;
154 $p->text("Hello world");
155 $p->cancel_emphasized_printing;
156  
157 my $formatted_output = $p->result;
158 # Send $formatted_output to printer
159  
160 =head1 Converting from 0.1.2 to 1.0.0
161  
162 =over 4
163  
164 =item * Create a L<Protocol::Star::Linemode> object instead of the L<Protocol::Star::Linemode::Generated> object
165  
166 =back
167  
168 =head1 AUTHOR
169  
170 Peter Stuifzand E<lt>peter@stuifzand.euE<gt>
171  
172 =head1 COPYRIGHT
173  
174 Copyright 2013 - Peter Stuifzand
175  
176 =head1 LICENSE
177  
178 This library is free software; you can redistribute it and/or modify
179 it under the same terms as Perl itself.
180  
181 =head1 SEE ALSO
182  
183 =cut
« Linemode/Generated.pm ↑ Summary