File Coverage

blib/lib/Business/TW/Invoice/U420.pm
Criterion Covered Total %
statement 12 47 25.5
branch 0 18 0.0
condition 0 2 0.0
subroutine 4 11 36.3
pod 7 7 100.0
total 23 85 27.0


line stmt bran cond sub pod time code
1             package Business::TW::Invoice::U420;
2              
3 1     1   24124 use warnings;
  1         2  
  1         31  
4 1     1   6 use strict;
  1         1  
  1         42  
5 1     1   6 use base ('Class::Accessor::Fast', 'Exporter');
  1         7  
  1         1679  
6              
7             __PACKAGE__->mk_accessors(qw(heading lines_available fh lines_used lines_total lines_stamp footer));
8              
9 1     1   3630 use constant ESC => "\x1b";
  1         2  
  1         583  
10              
11             =head1 NAME
12              
13             Business::TW::Invoice::U420 - Print Taiwan Unified Invoice with U420 printer
14              
15             =head1 VERSION
16              
17             Version 0.01
18              
19             =cut
20              
21             our $VERSION = '0.01';
22              
23             =head1 SYNOPSIS
24              
25             Business::TW::Invoice::U420->init_printer;
26             my $u420 = Business::TW::U420->new
27             ({ heading => [ DateTime->now->ymd, '',
28             'order: #232', ''],
29             lines_total => 35,
30             lines_available => 18,
31             lines_stamp => 5,
32             fh => \*STDOUT });
33              
34             $u420->println("123123") for 1..30;
35             $u420->cut;
36              
37             # to actually print to the printer, run:
38             # perl your-program.pl > COM1
39              
40              
41             =head1 DESCRIPTION
42              
43             This module generates commands for the C
44             printer for printing the Unified Invoice in Taiwan.
45              
46             You must install the driver and printer processor properly before you
47             can use the module.
48              
49             You can define multiple lines of headers that will appear on each page
50             of the printed invoices, and when you do println the module does all
51             the necessary paging and stamping for you.
52              
53             =head1 METHODS
54              
55             =head2 new
56              
57             =cut
58              
59             sub new {
60 0     0 1   my $class = shift;
61 0           my $self = $class->SUPER::new(@_);
62 0 0         $self->fh( \*STDOUT ) unless $self->fh;
63 0 0         $self->heading( [] ) unless $self->heading;
64 0 0         $self->footer( [] ) unless $self->footer;
65 0 0         $self->lines_total(35)
66             unless $self->lines_total;
67 0 0         $self->lines_available(18)
68             unless $self->lines_available;
69 0 0         $self->lines_stamp(5)
70             unless $self->lines_stamp;
71 0           return $self;
72             }
73              
74             =head2 init_printer
75              
76             =cut
77              
78             sub init_printer {
79 0     0 1   my $self = shift;
80 0           $self->print( ESC . '@');
81             }
82              
83             =head2 feed( $lines )
84              
85             Feed C<$lines> lines, default is 1.
86              
87             =cut
88              
89             sub feed {
90 0     0 1   my $self = shift;
91 0   0       my $lines = shift || 1;
92 0           $self->{lines_used} += $lines;
93 0           $self->print( ESC . 'd'. chr( $lines ) );
94             }
95              
96             =head2 stamp
97              
98             Make the printer stamp on the invoice. note that you generally don't
99             want to call this method directly, due to the stamp positioning. When
100             you call C, the module automatically detects the correct place to
101             stamp for the next invoice.
102              
103             =cut
104              
105             sub stamp {
106 0     0 1   my $self = shift;
107 0           $self->print( ESC . 'o' );
108             }
109              
110             =head2 cut
111              
112             feed the current invoice and cut, as well as stamping on the next
113             invoice.
114              
115             =cut
116              
117             sub cut {
118 0     0 1   my $self = shift;
119 0 0         return unless defined $self->lines_used;
120              
121 0           $self->feed( $self->lines_total - $self->lines_used + 1 );
122 0           $self->stamp;
123 0           $self->print( "\x0c" );
124 0           $self->lines_used(undef);
125             }
126              
127             =head2 print
128              
129             Low level print function.
130              
131             =cut
132              
133             sub print {
134 0     0 1   my $self = shift;
135 0           print {$self->fh} @_;
  0            
136             }
137              
138             =head2 println
139              
140             Print a line on the invoice. Does all the paging logic here.
141              
142             =cut
143              
144             sub println {
145 0     0 1   my $self = shift;
146 0 0         unless (defined $self->lines_used) {
147 0           $self->lines_used(0);
148 0           $self->feed( $self->lines_stamp );
149 0           $self->println($_) for @{$self->heading};
  0            
150             }
151 0           $self->print(@_, "\n");
152 0 0         if (++$self->{lines_used} == $self->lines_available + $self->lines_stamp ) {
153              
154 0           $self->cut;
155             }
156             }
157              
158             1;
159              
160             =head1 AUTHOR
161              
162             Chia-liang Kao, C<< >>
163              
164             =head2 TODO
165              
166             =over
167              
168             =item *
169              
170             Split the device control parts into C for
171             generic use and keep the paging/stamping logic here
172              
173             =item *
174              
175             Tests
176              
177             =item *
178              
179             Add footer support
180              
181             =back
182              
183             =head1 BUGS
184              
185             Please report any bugs or feature requests to
186             C, or through the web interface at
187             L.
188             I will be notified, and then you'll automatically be notified of progress on
189             your bug as I make changes.
190              
191             =head1 SUPPORT
192              
193             You can find documentation for this module with the perldoc command.
194              
195             perldoc Business::TW::Invoice::U420
196              
197             You can also look for information at:
198              
199             =over 4
200              
201             =item * AnnoCPAN: Annotated CPAN documentation
202              
203             L
204              
205             =item * CPAN Ratings
206              
207             L
208              
209             =item * RT: CPAN's request tracker
210              
211             L
212              
213             =item * Search CPAN
214              
215             L
216              
217             =back
218              
219             =head1 ACKNOWLEDGEMENTS
220              
221             =head1 COPYRIGHT & LICENSE
222              
223             Copyright 2007 AIINK co., ltd, all rights reserved.
224              
225             This program is free software; you can redistribute it and/or modify it
226             under the same terms as Perl itself.
227              
228             =cut
229              
230             1; # End of Business::TW::Invoice::U420