blib/lib/XML/Handler/Pdb.pm

filter: Statementstmt 23.4% 23 / 98 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 41.1% 7 / 17 Podpod 10.0% 1 / 10 totaltotal 15.9% 31 / 194 CC 30 SCAR 44.5
CC
30
Cov
14%
e_field
240.0
new
20.0
e_pdb
20.0
CRAP 85.8
↑ Summary
1 # $Id: Pdb.pm,v 1.4 2003/04/06 21:17:47 cvsjohan Exp $
2  
3 package XML::Handler::Pdb;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.2';
8  
9 1 ▶use base 'XML::Handler::Subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Palm::PDB;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Palm::Raw;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Temp 'tempfile';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
17 0 my ($proto, %arg) = @_;
18  
19 0 my $self = $proto->SUPER::new(%arg);
20  
21 0 ▶ $self->{_verbose} = $arg{Verbose} || 0;
Condition0%0/2
$arg{'Verbose'} || 0
l!l
00
MC/DC0%0/1
$arg{'Verbose'} || 0
$arg{'Verbose'}
Truth table0%0/2
A
A= $arg{'Verbose'}
Aresult
11
00
22  
23 0 ▶ print "Output to ", $self->{Output}, "\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
24  
25 0 ▶ if (!defined($self->{Output})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'Output'}) { } 0 0 0
26 0 ( $self->{_TempFH}, $self->{_Tempfile} ) = tempfile;
27 0 $self->{_Output} = $self->{_Tempfile};
28 } else {
29 0 $self->{_Output} = $self->{Output};
30 }
31 0 return $self;
32 }
33  
34 0 ▶sub s_pdb {
Subroutine s_pdb: not called CC=2 SCAR=17.9
Pod undocumented
35 0 my ($self, $el) = @_;
36  
37 0 ▶ print "start pdb\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
38  
39 0 my $pdb = Palm::Raw->new;
40 0 $pdb->{"name"} = $el->{Attributes}{"{}name"}{Value};
41 0 $pdb->{"type"} = "DATA";
42 0 $pdb->{"creator"} = $el->{Attributes}{"{}creator"}{Value};
43 0 $self->{_pdb} = $pdb;
44 }
45  
46 0 ▶sub e_pdb {
Subroutine e_pdb: not called CC=4 SCAR=30.0
Pod undocumented
47 0 my ($self, $el) = @_;
48  
49 0 ▶ print "end pdb\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
50  
51 0 $self->{_pdb}->Write($self->{_Output});
52 0 ▶ if (defined $self->{_TempFH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_TempFH"}) 0 0 0
53 0 my $fh = $self->{_TempFH};
54 0 my $buf;
55 0 ▶ while ($fh->read($buf, 2048)) { print $buf };
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->read($buf, 2048)) 0 0 0
56 0 $fh->close;
57 }
58 0 $self->{_pdb} = undef;
59 }
60  
61 0 ▶sub s_record {
Subroutine s_record: not called CC=3 SCAR=24.8
Pod undocumented
62 0 my ($self, $el) = @_;
63  
64 0 ▶ print "start record\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
65
66 0 $self->{_actual_record} = $self->{_pdb}->new_Record;
67 $self->{_actual_record}->{"category"}
68 0 ▶ = $el->{Attributes}{"{}category"}{Value} || 0;
Condition0%0/2
$el->{'Attributes'}{'{}category'}{'Value'} || 0
l!l
00
MC/DC0%0/1
$el->{'Attributes'}{'{}category'}{'Value'} || 0
$el->{'Attributes'}{'{}category'}{'Value'}
Truth table0%0/2
A
A= $el->{'Attributes'}{'{}category'}{'Value'}
Aresult
11
00
69 }
70  
71 0 ▶sub e_record {
Subroutine e_record: not called CC=2 SCAR=17.9
Pod undocumented
72 0 my ($self, $el) = @_;
73  
74 0 ▶ print "end record\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
75  
76 0 $self->{_pdb}->append_Record($self->{_actual_record});
77 0 $self->{actual_record} = undef;
78 }
79  
80 0 ▶sub s_field {
Subroutine s_field: not called CC=3 SCAR=24.8
Pod undocumented
81 0 my ($self, $el) = @_;
82  
83 0 ▶ print "start field\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
84  
85 0 my $type = $el->{Attributes}{"{}type"}{Value};
86 0 $self->{_field_type} = $type;
87  
88 0 ▶ if (exists($el->{Attributes}{"{}value"})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{}value"}) 0 0 0
89 0 $self->{_field_value} = $el->{Attributes}{"{}value"}{Value};
90 }
91 }
92  
93 0 ▶sub e_field {
Subroutine e_field: not called CC=15 SCAR=54.8
Pod undocumented
94 0 my ($self, $element) = @_;
95  
96 0 my $data;
97 0 my $type = $self->{_field_type};
98  
99 0 ▶ print "type := $type\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
100 0 ▶ if ($self->{_verbose} && defined $self->{_field_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_verbose"} and defined $self->{"_field_value"}) 0 0 0
Condition0%0/3
$self->{"_verbose"} and defined $self->{"_field_value"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_verbose"} and defined $self->{"_field_value"}
$self->{"_verbose"} defined $self->{"_field_value"}
Truth table0%0/3
A and B
A= $self->{"_verbose"}B= defined $self->{"_field_value"}
ABresult
0X0
100
111
101 0 print "value := ", $self->{_field_value}, "\n";
102 }
103 0 ▶ if ($self->{_verbose} && defined $self->{_chars}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_verbose"} and defined $self->{"_chars"}) 0 0 0
Condition0%0/3
$self->{"_verbose"} and defined $self->{"_chars"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_verbose"} and defined $self->{"_chars"}
$self->{"_verbose"} defined $self->{"_chars"}
Truth table0%0/3
A and B
A= $self->{"_verbose"}B= defined $self->{"_chars"}
ABresult
0X0
100
111
104 0 print "value := ", $self->{_chars}, "\n";
105 }
106  
107 # For each type, transform the type to the NSBasic equivalent ...
108 #
109 0 ▶ if ($type eq 'text') {
Branch: 7 branches
BranchTrueFalseTotal
if ($type eq 'text') { } 0 0 0
elsif ($type eq 'int') { } 0 0 0
elsif ($type eq 'date') { } 0 0 0
elsif ($type eq 'time') { } 0 0 0
elsif ($type eq 'byte') { } 0 0 0
elsif ($type eq 'float' or $type eq 'double') { } 0 0 0
elsif ($type eq 'short') { } 0 0 0
110 # Text does not need processing
111 0 $data = $self->{_chars} . "\0";
112 } elsif ($type eq 'int') {
113 # Int is stored i/t attribute
114 0 $data = pack("N", $self->{_field_value});
115 } elsif ($type eq 'date') {
116 # Date
117 my $packed = pack("d",
118 0 $self->convert_date_to_nsbasic($self->{_field_value}));
119 0 $data = pack("C*", reverse unpack("C*", $packed));
120 } elsif ($type eq 'time') {
121 # Time
122 my $packed = pack("d",
123 0 $self->convert_time_to_nsbasic($self->{_field_value}));
124 0 $data = pack("C*", reverse unpack("C*", $packed));
125 } elsif ($type eq 'byte') {
126 # Byte
127 0 $data = pack("C", $self->{_field_value});
128 ▶ } elsif ($type eq 'float' || $type eq 'double') {
Condition0%0/3
$type eq "float" or $type eq "double"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "float" or $type eq "double"
$type eq "float" $type eq "double"
Truth table0%0/3
A or B
A= $type eq "float"B= $type eq "double"
ABresult
1X1
011
000
129 # Float and double
130 0 my $packed = pack("d", $self->{_field_value});
131 0 $data = pack("C*", reverse unpack("C*", $packed));
132 } elsif ($type eq 'short') {
133 # 16 bit signed int
134 0 $data = pack("n", $self->{_field_value});
135 }
136 0 $self->{_chars} = undef;
137 0 $self->{_field_type} = undef;
138 0 $self->{_field_value} = undef;
139 0 $self->{_actual_record}->{"data"} .= $data;
140  
141 0 ▶ print "end field\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
142 }
143  
144 0 ▶sub characters {
Subroutine characters: not called CC=4 SCAR=30.0
Pod undocumented
145 0 my ($self,$chars) = @_;
146  
147 0 ▶ print "characters ...\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
148  
149 0 ▶ return unless $self->in_element('field');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_element("field") 0 0 0
150
151 0 ▶ print "characters in field ...\n" if $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_verbose"} 0 0 0
152  
153 0 $self->{_chars} .= $chars->{Data};
154 }
155  
156 0 ▶sub convert_date_to_nsbasic {
Subroutine convert_date_to_nsbasic: not called CC=1 SCAR=6.9
Pod undocumented
157 0 my ($self, $rawdate) = @_;
158
159 0 my ($year, $month, $day) = ( $rawdate =~ /(\d+)-(\d+)-(\d+)/ );
160 0 return ($year-1900)*10000+$month*100+$day;
161 }
162  
163 0 ▶sub convert_time_to_nsbasic {
Subroutine convert_time_to_nsbasic: not called CC=1 SCAR=6.9
Pod undocumented
164 0 my ($self, $rawdate) = @_;
165  
166 0 my ($hour, $minute, $second) = ( $rawdate =~ /(\d+):(\d+):(\d+)/ );
167 0 return $hour*10000+$minute*100+$second;
168 }
169  
170 1 1;
171  
172 __END__
↑ Summary