line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PITA::XML::Storable; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# A PITA::XML class that can be loaded from and saved to a file |
4
|
|
|
|
|
|
|
|
5
|
10
|
|
|
10
|
|
50
|
use strict; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
349
|
|
6
|
10
|
|
|
10
|
|
50
|
use Params::Util qw{ _INSTANCE }; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
788
|
|
7
|
|
|
|
|
|
|
|
8
|
10
|
|
|
10
|
|
90
|
use vars qw{$VERSION}; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
420
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
10
|
|
|
10
|
|
2819
|
$VERSION = '0.52'; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
##################################################################### |
18
|
|
|
|
|
|
|
# Main Methods |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub read { |
21
|
6
|
|
|
6
|
0
|
4078
|
my $class = shift; |
22
|
6
|
|
|
|
|
48
|
my $fh = PITA::XML->_FH(shift); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
### NOTE: DISABLED TILL WE FINALIZE THE SCHEMA |
25
|
|
|
|
|
|
|
# Validate the document and reset the handle |
26
|
|
|
|
|
|
|
# $class->validate( $fh ); |
27
|
|
|
|
|
|
|
# $fh->seek( 0, 0 ) or Carp::croak( |
28
|
|
|
|
|
|
|
# 'Failed to reset file after validation (seek to 0)' |
29
|
|
|
|
|
|
|
# ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Build the object from the file and validate |
32
|
6
|
|
|
|
|
25
|
my $self = bless { }, $class; |
33
|
6
|
|
|
|
|
59
|
my $parser = XML::SAX::ParserFactory->parser( |
34
|
|
|
|
|
|
|
Handler => PITA::XML::SAXParser->new( $self ), |
35
|
|
|
|
|
|
|
); |
36
|
6
|
|
|
|
|
261533
|
$parser->parse_file($fh); |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
|
|
1446
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub write { |
42
|
6
|
|
|
6
|
0
|
568
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Prepate the driver params |
45
|
6
|
50
|
|
|
|
60
|
my @params = _INSTANCE($_[0], 'XML::SAX::Base') |
|
|
50
|
|
|
|
|
|
46
|
|
|
|
|
|
|
? ( Handler => shift ) |
47
|
|
|
|
|
|
|
: defined($_[0]) |
48
|
|
|
|
|
|
|
? ( Output => shift ) |
49
|
|
|
|
|
|
|
: Carp::croak("Did not provide an output destination to ->write"); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Create the SAX Driver |
52
|
6
|
|
|
|
|
136
|
my $driver = PITA::XML::SAXDriver->new( @params ); |
53
|
6
|
50
|
|
|
|
24
|
unless ( $driver ) { |
54
|
0
|
|
|
|
|
0
|
die("Failed to create SAXDriver for report"); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Parse ourself with the driver to driver the writing |
58
|
|
|
|
|
|
|
# of the output. |
59
|
6
|
|
|
|
|
37
|
$driver->parse( $self ); |
60
|
|
|
|
|
|
|
|
61
|
6
|
|
|
|
|
356
|
return 1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |