ESCPOS/Debug.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 42 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
AUTOLOAD
2.0
as_perl_code
2.0
CRAP 2.0
1 package XML::Printer::ESCPOS::Debug;
2  
3 use strict;
4 use warnings;
5 use Data::Dumper;
6  
7 our $VERSION = '0.04';
8  
9 our $AUTOLOAD;
10  
11 =head2 new
12  
13 Constructs a debug printer object.
14  
15 =cut
16  
17 sub new {
18 return bless { calls => [], }, $_[0];
19 }
20  
21 =head2 AUTOLOAD
22  
23 Logs all calls to the printer object.
24  
25 =cut
26  
27 sub AUTOLOAD {
28 my ( $self, @params ) = @_;
29 my $method = $AUTOLOAD;
30 $method =~ s/^.*:://;
31 push @{ $self->{calls} } => [ $method => @params ];
32 }
33  
34 =head2 as_perl_code
35  
36 Returns all calls to the printer as perl code.
37  
38 =cut
39  
40 sub as_perl_code {
41 my $self = shift;
42 my $devicevar = shift || '$device';
43 {
44 local $Data::Dumper::Terse = 1;
45 return join '' => map {
46 my $method = shift @$_;
47 my $paramlist = Data::Dumper->Dump( [$_], [qw(*ary)] );
48 $paramlist =~ s/\s+$//gm;
49 $devicevar . '->printer->' . $method . $paramlist . ";\n";
50 } @{ $self->{calls} };
51 }
52 }
53  
54 1;