Barcode/NW7.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 73 CC 5 SCAR 16.7
CC
5
Cov
0%
plot
12.0
new
6.0
init
6.0
CRAP 5.3
1 package GD::Barcode::NW7;
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=1.10;
9 my $nw7Bar = {
10 '0' => '0000011',
11 '1' => '0000110',
12 '2' => '0001001',
13 '3' => '1100000',
14 '4' => '0010010',
15 '5' => '1000010',
16 '6' => '0100001',
17 '7' => '0100100',
18 '8' => '0110000',
19 '9' => '1001000',
20 '-' => '0001100',
21 '$' => '0011000',
22 ':' => '1000101',
23 '/' => '1010001',
24 '.' => '1010100',
25 '+' => '0010101',
26 'A' => '0011010',
27 'B' => '0101001',
28 'C' => '0001011',
29 'D' => '0001110'
30 };
31 #------------------------------------------------------------------------------
32 # new (for GD::Barcode::NW7)
33 #------------------------------------------------------------------------------
34 sub new($$) {
35 my($sClass, $sTxt) = @_;
36 $errStr ='';
37 my $oThis = {};
38 bless $oThis;
39 return undef if($errStr = $oThis->init($sTxt));
40 return $oThis;
41 }
42 #------------------------------------------------------------------------------
43 # init (for GD::Barcode::NW7)
44 #------------------------------------------------------------------------------
45 sub init($$\%){
46 my($oThis, $sTxt) =@_;
47 #Check
48 return 'Invalid Characters' if($sTxt =~ /[^0-9\-\$:\/.+ABCD]/);
49  
50 #CalcCd
51 $oThis->{text} = $sTxt;
52 return '';
53 }
54 #------------------------------------------------------------------------------
55 # barcode (for GD::Barcode::NW7)
56 #------------------------------------------------------------------------------
57 sub barcode($) {
58 my($oThis) = @_;
59 my($sWk, $sRes);
60  
61 my $sTxt = $oThis->{text};
62 $sRes = '';
63 foreach $sWk (split(//, $sTxt)) {
64 $sRes .= GD::Barcode::dumpCode( $nw7Bar->{$sWk} .'0' );
65 }
66 return $sRes;
67 }
68 #------------------------------------------------------------------------------
69 # plot (for GD::Barcode::NW7)
70 #------------------------------------------------------------------------------
71 sub plot($%) {
72 my($oThis, %hParam) =@_;
73  
74 my $sTxt = $oThis->{text};
75 my $sPtn = $oThis->barcode();
76 #Create Image
77 my $iHeight = ($hParam{Height})? $hParam{Height} : 50;
78 my ($oGd, $cBlack);
79 if($hParam{NoText}) {
80 ($oGd, $cBlack) = GD::Barcode::plot($sPtn, length($sPtn), $iHeight, 0, 0);
81 }
82 else {
83 my($fW,$fH) = (GD::Font->Small->width, GD::Font->Small->height);
84 my $iWidth = length($sPtn);
85 #Bar Image
86 ($oGd, $cBlack) = GD::Barcode::plot($sPtn, $iWidth, $iHeight, $fH, 0);
87  
88 #String
89 $oGd->string(GD::Font->Small, (length($sPtn)-$fW*(length($sTxt)))/2, $iHeight - $fH,
90 $sTxt, $cBlack);
91 }
92 return $oGd;
93 }
94 1;
95 __END__