| 1 | # $Id: XML.pm 456 2009-04-15 12:20:59Z fil $ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package Data::Tabular::Dumper::XML; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Data::Tabular::Dumper::Writer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use vars qw( @ISA ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | @ISA = qw( Data::Tabular::Dumper::Writer ); | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 11 | sub open | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | my($package, $param)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | my($file, $top, $record)=@$param; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | my $self = $package->SUPER::open( $file ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | $top||='DATA'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$top ||= "DATA"
MC/DC0%0/1
$top ||= "DATA"
$top
Truth table50%1/2
A
A= $top
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 13 | ▶ | $record||='RECORD'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$record ||= "RECORD"
MC/DC100%1/1
$record ||= "RECORD"
$record
Truth table100%2/2
A
A= $record
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | my $fh = $self->{fh}; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 13 | print $fh qq(<?xml version="1.0" encoding="iso-8859-1"?>\n<$top>\n); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | $self->{top} = $top; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 13 | $self->{record} = $record; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 13 | $self->{prefix} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 13 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 32 | sub close | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 26 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 26 | my($self)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 26 | my $fh = delete $self->{fh}; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 26 | ▶ | return unless $fh; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 13 | print $fh qq(</$self->{top}>\n) ; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 41 | sub fields | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 11 | my($self, $fields)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 11 | $self->{fields}=[@$fields]; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 48 | sub write | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 37 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 37 | my($self, $data)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 37 | my $fh=$self->{fh}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 37 | my $record = $self->{record}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 37 | my $q = 0; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 37 | ▶ | if( 1 < @{$self->{fields}} and $self->{fields}[0] eq '' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
1 < @{$self->{"fields"};} and $self->{"fields"}[0] eq "" and $data->[0] ne ""
1 < @{$self->{"fields"};} and $self->{"fields"}[0] eq ""
MC/DC66%2/3
1 < @{$self->{"fields"};} and $self->{"fields"}[0] eq "" and $data->[0] ne ""
1 < @{$self->{"fields"};}
$self->{"fields"}[0] eq ""
$data->[0] ne ""
Truth table75%3/4
A and B and C
A= 1 < @{$self->{"fields"};}B= $self->{"fields"}[0] eq ""C= $data->[0] ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | and $data->[0] ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | $record = $data->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | $q++; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 37 | print $fh qq($self->{prefix} <$record>\n); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 37 | ▶ | for( ; $q <=$#$data ; $q++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 132 | ▶ | my $f = $self->{fields}[$q > $#{$self->{fields}} ? -1 : $q]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 132 | ▶ | $f = $q if not defined $f or $f eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $f or $f eq ""
MC/DC50%1/2
not defined $f or $f eq ""
not defined $f
$f eq ""
Truth table66%2/3
not(A) or B
A= not defined $fB= $f eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 132 | my $d=$data->[$q]; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 132 | ▶ | next unless defined $d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 100 | $d=~s/&/&/g; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 100 | $d=~s/</</g; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 100 | $d=~s/>/>/g; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 100 | print $fh qq($self->{prefix} <$f>$d</$f>\n); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 37 | print $fh qq($self->{prefix} </$record>\n); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 77 | sub page_start | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 10 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
page_start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 10 | my( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 10 | $self->{prefix} .= ' '; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | $name =~ s/\W/_/g; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 10 | my $fh=$self->{fh}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 10 | print $fh "$self->{prefix}<$name>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 88 | sub page_end | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
page_end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 10 | my( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 10 | $name =~ s/\W/_/g; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 10 | my $fh=$self->{fh}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 10 | print $fh "$self->{prefix}</$name>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 10 | substr( $self->{prefix} , -2 ) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||||||||||||||||||||||||