Barcode/COOP2of5.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 96 CC 7 SCAR 18.7
CC
7
Cov
0%
barcodeWk
12.0
plot
12.0
new
6.0
CRAP 6.5
1 package GD::Barcode::COOP2of5;
2 use strict;
3 BEGIN { eval{require 'GD.pm';}; };
4 use GD::Barcode;
5 require Exporter;
6 use vars qw($VERSION @ISA $errStr);
7 @ISA = qw(GD::Barcode Exporter);
8 $VERSION=0.01;
9 #------------------------------------------------------------------------------
10 # new (for GD::Barcode::COOP2of5)
11 #------------------------------------------------------------------------------
12 sub new($$) {
13 my($sClass, $sTxt) = @_;
14 $errStr ='';
15 my $oThis = {};
16 bless $oThis;
17 return undef if($errStr = $oThis->init($sTxt));
18 return $oThis;
19 }
20 #------------------------------------------------------------------------------
21 # init (for GD::Barcode::COOP2of5)
22 #------------------------------------------------------------------------------
23 sub init($$){
24 my($oThis, $sTxt) =@_;
25 #Check
26 return 'Invalid Characters' if($sTxt =~ /[^0-9]/);
27  
28 $oThis->{text} = $sTxt;
29 return '';
30 }
31 #------------------------------------------------------------------------------
32 # new (for GD::Barcode::COOP2of5)
33 #------------------------------------------------------------------------------
34 sub barcodeWk($) {
35 my($sPtn) =@_;
36 my $sRes = '';
37 my $sClr = '1';
38 for(my $i=0; $i< length($sPtn); $i++) {
39 $sRes .= (substr($sPtn, $i, 1) eq '1')? $sClr x 3 : $sClr;
40 $sClr = ($sClr eq '1')? '0': '1';
41 }
42 return $sRes;
43 }
44 sub barcode($) {
45 my ($oThis) = @_;
46 my $i;
47 my $sRes;
48 my $sTxt = $oThis->{text};
49 my $rhPtn ={
50 'START' => '101',
51 '0' => '11000',
52 '1' => '00011',
53 '2' => '00101',
54 '3' => '00110',
55 '4' => '01001',
56 '5' => '01010',
57 '6' => '01100',
58 '7' => '10001',
59 '8' => '10010',
60 '9' => '10100',
61 'STOP' => '011',
62 };
63 $sRes = barcodeWk($rhPtn->{START});
64 for( $i = 0; $i < length($sTxt); $i++ ){
65 $sRes .= '0'; #GAP
66 $sRes .= barcodeWk($rhPtn->{substr($sTxt, $i, 1)});
67 }
68 $sRes .= '0'; #GAP
69 $sRes .= barcodeWk($rhPtn->{STOP});
70 return $sRes;
71 }
72  
73 #------------------------------------------------------------------------------
74 # plot (for GD::Barcode::COOP2of5)
75 #------------------------------------------------------------------------------
76 sub plot($;%) {
77 my($oThis, %hParam) =@_;
78  
79 my $sTxtWk = $oThis->{text};
80 my $sPtn = $oThis->barcode();
81  
82 #Create Image
83 my $iHeight = ($hParam{Height})? $hParam{Height} : 50;
84 my($oGd, $cBlack);
85 if($hParam{NoText}) {
86 ($oGd, $cBlack) = GD::Barcode::plot($sPtn, length($sPtn), $iHeight, 0, 0);
87 }
88 else {
89 my($fW,$fH) = (GD::Font->Small->width, GD::Font->Small->height);
90 my $iWidth = length($sPtn);
91 #Bar Image
92 ($oGd, $cBlack) = GD::Barcode::plot($sPtn, $iWidth, $iHeight, $fH, 0);
93  
94 #String
95 $oGd->string(GD::Font->Small, (length($sPtn)-$fW*(length($sTxtWk)))/2, $iHeight - $fH,
96 $sTxtWk, $cBlack);
97 }
98 return $oGd;
99 }
100 1;
101 __END__