| 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
MC/DC0%0/1
$arg{'Verbose'} || 0
$arg{'Verbose'}
Truth table0%0/2
A
A= $arg{'Verbose'}
| |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | print "Output to ", $self->{Output}, "\n" if $self->{_verbose}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if (!defined($self->{Output})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | 0 | $self->{_pdb}->Write($self->{_Output}); | |||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (defined $self->{_TempFH}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 53 | 0 | my $fh = $self->{_TempFH}; | |||||||||||||||||||||||||||||||||
| 54 | 0 | my $buf; | |||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | while ($fh->read($buf, 2048)) { print $buf }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$el->{'Attributes'}{'{}category'}{'Value'} || 0
$el->{'Attributes'}{'{}category'}{'Value'}
Truth table0%0/2
A
A= $el->{'Attributes'}{'{}category'}{'Value'}
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($self->{_verbose} && defined $self->{_field_value}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_verbose"} and defined $self->{"_field_value"}
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"}
| |||||||||||||||||||||||||||||||||||
| 101 | 0 | print "value := ", $self->{_field_value}, "\n"; | |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($self->{_verbose} && defined $self->{_chars}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_verbose"} and defined $self->{"_chars"}
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"}
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | return unless $self->in_element('field'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | print "characters in field ...\n" if $self->{_verbose}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||