Barcode.pm

filter: Statementstmt 73.2% 41 / 56 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 50.0% 2 / 4 totaltotal 71.6% 58 / 81 SCAR 25.3
CC
10
Cov
71%
plot
20.0
dumpCode
4.0
new
3.0
CRAP 12.5
« Barcode/EAN8.pm ↑ Summary Barcode/COOP2of5.pm »
1 package GD::Barcode;
2 13 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use vars qw( @ISA $errStr);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 our $VERSION = '2.00';
9  
10 sub new {
11 11 ▶ my ( $sClass, $sType, $sTxt, $rhPrm ) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
12 11 my $oThis = {};
13 11 my $module = "GD::Barcode::$sType";
14 11 eval "require $module;";
15 11 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 10 11
16 1 $errStr = "Can't load $sType : $@";
17 1 return;
18 }
19 10 bless $oThis, $module;
20 10 ▶ return if ( $errStr = $oThis->init( $sTxt, $rhPrm ) );
Branch: 1 branch
BranchTrueFalseTotal
if $GD::Barcode::errStr = $oThis->init($sTxt, $rhPrm) 0 10 10
21 10 return $oThis;
22 }
23  
24 sub barPtn {
25 62 ▶ my ( $bar, $table ) = @_;
Subroutine barPtn: called CC=2 SCAR=6.9
Pod undocumented
26 62 my $sRes;
27  
28 62 $sRes = '';
29 62 foreach my $sWk ( split( //, $bar ) ) {
30 62 $sRes .= $table->{$sWk};
31 }
32 62 return $sRes;
33 }
34  
35 sub dumpCode {
36 16 ▶ my ($sCode) = @_;
Subroutine dumpCode: called CC=4 SCAR=13.9
Pod undocumented
37 16 my ( $sRes, $sClr );
38  
39 #Init
40 16 $sRes = '';
41 16 $sClr = '1'; # 1: Black, 0:White
42  
43 16 foreach my $sWk ( split( //, $sCode ) ) {
44 142 ▶ $sRes .= ( $sWk eq '1' ) ? $sClr x 3 : $sClr; #3 times or Normal
Branch: 1 branch
BranchTrueFalseTotal
$sWk eq '1' ? : 46 96 142
45 142 ▶ $sClr = ( $sClr eq '0' ) ? '1' : '0';
Branch: 1 branch
BranchTrueFalseTotal
$sClr eq '0' ? : 71 71 142
46 }
47 16 return $sRes;
48 }
49  
50 sub plot {
51 0 ▶ my ( $sBarcode, $iWidth, $iHeight, $fH, $iStart ) = @_;
Subroutine plot: not called CC=4 SCAR=30.0
Pod documented
52  
53 #Create Image
54 0 my ( $gdNew, $cWhite, $cBlack );
55 0 eval {
56 0 $gdNew = GD::Image->new( $iWidth, $iHeight );
57 0 $cWhite = $gdNew->colorAllocate( 255, 255, 255 );
58 0 $cBlack = $gdNew->colorAllocate( 0, 0, 0 );
59 0 $gdNew->filledRectangle( 0, 0, $iWidth, $iHeight, $cWhite );
60  
61 0 my $iPos = $iStart;
62 0 foreach my $cWk ( split( //, $sBarcode ) ) {
63 0 ▶ if ( $cWk eq '0' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cWk eq '0') { } 0 0 0
elsif ($cWk eq 'G') { } 0 0 0
64 0 $gdNew->line( $iPos, 0, $iPos, $iHeight - $fH, $cWhite );
65 }
66 elsif ( $cWk eq 'G' ) {
67 0 $gdNew->line( $iPos, 0, $iPos, $iHeight - 2 * ( $fH / 3 ),
68 $cBlack );
69 }
70 else { #$cWk eq "1" etc.
71 0 $gdNew->line( $iPos, 0, $iPos, $iHeight - $fH, $cBlack );
72 }
73 0 $iPos++;
74 }
75 };
76 0 return ( $gdNew, $cBlack );
77 }
78 13 1;
79 __END__
« Barcode/EAN8.pm ↑ Summary Barcode/COOP2of5.pm »