Barcode/Industrial2of5.pm untested

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 92 CC 6 SCAR 16.8
CC
6
Cov
0%
plot
12.0
new
6.0
init
6.0
CRAP 5.4
1 package GD::Barcode::Industrial2of5;
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::Industrial2of5)
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::Industrial2of5)
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::Industrial2of5)
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 $sRes .= '0'
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' => '110',
51 '0' => '00110',
52 '1' => '10001',
53 '2' => '01001',
54 '3' => '11000',
55 '4' => '00101',
56 '5' => '10100',
57 '6' => '01100',
58 '7' => '00011',
59 '8' => '10010',
60 '9' => '01010',
61 'STOP' => '101',
62 };
63 $sRes = barcodeWk($rhPtn->{START});
64 for( $i = 0; $i < length($sTxt); $i++ ){
65 $sRes .= barcodeWk($rhPtn->{substr($sTxt, $i, 1)});
66 }
67 $sRes .= barcodeWk($rhPtn->{STOP});
68 return substr($sRes, 0, length($sRes)- 1);
69 }
70  
71 #------------------------------------------------------------------------------
72 # plot (for GD::Barcode::Industrial2of5)
73 #------------------------------------------------------------------------------
74 sub plot($;%) {
75 my($oThis, %hParam) =@_;
76  
77 my $sTxtWk = $oThis->{text};
78 my $sPtn = $oThis->barcode();
79  
80 #Create Image
81 my $iHeight = ($hParam{Height})? $hParam{Height} : 50;
82 my($oGd, $cBlack);
83 if($hParam{NoText}) {
84 ($oGd, $cBlack) = GD::Barcode::plot($sPtn, length($sPtn), $iHeight, 0, 0);
85 }
86 else {
87 my($fW,$fH) = (GD::Font->Small->width, GD::Font->Small->height);
88 my $iWidth = length($sPtn);
89 #Bar Image
90 ($oGd, $cBlack) = GD::Barcode::plot($sPtn, $iWidth, $iHeight, $fH, 0);
91  
92 #String
93 $oGd->string(GD::Font->Small, (length($sPtn)-$fW*(length($sTxtWk)))/2, $iHeight - $fH,
94 $sTxtWk, $cBlack);
95 }
96 return $oGd;
97 }
98 1;
99 __END__