File Coverage

blib/lib/EPL2/Pad.pm
Criterion Covered Total %
statement 38 38 100.0
branch n/a
condition n/a
subroutine 15 15 100.0
pod n/a
total 53 53 100.0


line stmt bran cond sub pod time code
1             package EPL2::Pad;
2             # ABSTRACT: Pad (Describe Printer Label)
3             $EPL2::Pad::VERSION = '0.001';
4 2     2   3065 use 5.010;
  2         4  
5 2     2   6 use Moose;
  2         3  
  2         11  
6 2     2   9269 use MooseX::Method::Signatures;
  2         819306  
  2         12  
7 2     2   267 use namespace::autoclean;
  2         3  
  2         12  
8 2     2   104 use EPL2::Types qw(Padwidth Padheight Natural Positive);
  2         2  
  2         18  
9              
10 2     2   4694 use EPL2::Command::A;
  2         4  
  2         60  
11 2     2   489 use EPL2::Command::B;
  2         4  
  2         49  
12 2     2   833 use EPL2::Command::O;
  2         4  
  2         57  
13 2     2   868 use EPL2::Command::N;
  2         4  
  2         59  
14 2     2   882 use EPL2::Command::Q;
  2         5  
  2         62  
15 2     2   947 use EPL2::Command::qq;
  2         4  
  2         62  
16 2     2   957 use EPL2::Command::P;
  2         4  
  2         231  
17              
18             #Public Attributes
19             has continuous => ( is => 'rw', isa => 'Bool', default => 1, );
20             has number_sets => ( is => 'rw', isa => Natural, default => 1, );
21             has number_copies => ( is => 'rw', isa => Natural, default => 0, );
22             has clear_image_buffer => ( is => 'rw', isa => 'Bool', default => 1, );
23             has height => ( is => 'rw', isa => Padheight, default => 0, );
24             has width => ( is => 'rw', isa => Padwidth, default => 0, );
25              
26             #Private Attributes
27             has commands => ( is => 'ro', isa => 'ArrayRef', default => sub { []; }, init_arg => undef, );
28              
29             #Methods
30 2     2   70757 method add_command( EPL2::Command $command ) {
31             push @{ $self->commands }, $command;
32             }
33              
34 2     2   29800 method process () {
35             my ( $needed_height, @com ) = ( $self->height );
36             for my $com ( @{ $self->commands } ) {
37             my $this_height = 0;
38             if ( blessed $com eq 'EPL2::Command::A' ) {
39             $this_height = $com->height + $com->v_pos;
40             $needed_height = $this_height if ( $this_height > $needed_height );
41             }
42             push @com, $com;
43             }
44              
45             if ( $self->continuous || $self->height ) {
46             my $height = $self->height;
47             if ( $self->continuous ) {
48             $height += $needed_height;
49             }
50             unshift @com, EPL2::Command::Q->new( height => $height );
51             }
52              
53             unshift @com, EPL2::Command::qq->new( width => $self->width ) if ( $self->width );
54             unshift @com, EPL2::Command::O->new;
55             unshift @com, EPL2::Command::N->new if ( $self->clear_image_buffer );
56             push @com, EPL2::Command::P->new( number_sets => $self->number_sets, number_copies => $self->number_copies );
57             return @com;
58             }
59              
60 2     2   91587 method string ( Str :$delimiter = "\n" ) {
61             my $string = '';
62             for my $com ( $self->process ) {
63             $string .= $com->string( delimiter => $delimiter );
64             }
65             return $string;
66             }
67              
68             __PACKAGE__->meta->make_immutable;
69              
70             1;
71              
72             __END__
73              
74             =pod
75              
76             =encoding UTF-8
77              
78             =head1 NAME
79              
80             EPL2::Pad - Pad (Describe Printer Label)
81              
82             =head1 VERSION
83              
84             version 0.001
85              
86             =head1 SEE ALSO
87              
88             L<EPL2>
89              
90             L<EPL2::Types>
91              
92             =head1 AUTHOR
93              
94             Ted Katseres <tedkat@cpan.org>
95              
96             =head1 COPYRIGHT AND LICENSE
97              
98             This software is copyright (c) 2016 by Ted Katseres.
99              
100             This is free software; you can redistribute it and/or modify it under
101             the same terms as the Perl 5 programming language system itself.
102              
103             =cut