line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::XMetaL::Factory;
|
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
265709
|
use strict;
|
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
897
|
|
4
|
6
|
|
|
6
|
|
35
|
use warnings;
|
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
1445
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
61
|
use Carp;
|
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
1468
|
|
7
|
6
|
|
|
6
|
|
7741
|
use Hash::Util qw(lock_keys);
|
|
6
|
|
|
|
|
21332
|
|
|
6
|
|
|
|
|
51
|
|
8
|
6
|
|
|
6
|
|
3397
|
use Switch;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Win32::OLE;
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use constant XMETAL_NO_SAVE => 2;
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new {
|
14
|
|
|
|
|
|
|
my ($class) = @_;
|
15
|
|
|
|
|
|
|
my $self;
|
16
|
|
|
|
|
|
|
eval {
|
17
|
|
|
|
|
|
|
$self = bless {
|
18
|
|
|
|
|
|
|
_xmetal => undef,
|
19
|
|
|
|
|
|
|
}, ref($class) || $class;
|
20
|
|
|
|
|
|
|
lock_keys(%$self, keys %$self);
|
21
|
|
|
|
|
|
|
$self->_create_xmetal();
|
22
|
|
|
|
|
|
|
};
|
23
|
|
|
|
|
|
|
croak $@ if $@;
|
24
|
|
|
|
|
|
|
return $self;
|
25
|
|
|
|
|
|
|
}
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub get_xmetal_path {
|
28
|
|
|
|
|
|
|
my ($self) = @_;
|
29
|
|
|
|
|
|
|
my $xmetal = $self->_get_xmetal();
|
30
|
|
|
|
|
|
|
my $path = $xmetal->{Path};
|
31
|
|
|
|
|
|
|
return $path;
|
32
|
|
|
|
|
|
|
}
|
33
|
|
|
|
|
|
|
sub _get_xmetal {$_[0]{_xmetal}}
|
34
|
|
|
|
|
|
|
sub _set_xmetal {$_[0]{_xmetal} = $_[1]}
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _get_documents {
|
37
|
|
|
|
|
|
|
my ($self) = @_;
|
38
|
|
|
|
|
|
|
my $xmetal = $self->_get_xmetal(); |
39
|
|
|
|
|
|
|
return $xmetal->{Documents};
|
40
|
|
|
|
|
|
|
}
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub create_xmetal {
|
43
|
|
|
|
|
|
|
my ($self, @documents) = @_;
|
44
|
|
|
|
|
|
|
eval {
|
45
|
|
|
|
|
|
|
my $documents = $self->_get_documents();
|
46
|
|
|
|
|
|
|
my $document;
|
47
|
|
|
|
|
|
|
foreach my $document (@documents) {
|
48
|
|
|
|
|
|
|
chomp $document;
|
49
|
|
|
|
|
|
|
if ( $document =~ /^<\?xml/i) {
|
50
|
|
|
|
|
|
|
$document = $self->_create_document_from_string($document); |
51
|
|
|
|
|
|
|
} elsif (-f $document) {
|
52
|
|
|
|
|
|
|
$document = $self->_create_document_from_path($document); |
53
|
|
|
|
|
|
|
};
|
54
|
|
|
|
|
|
|
die "Could not open document" unless ref($document);
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
};
|
57
|
|
|
|
|
|
|
croak $@ if $@;
|
58
|
|
|
|
|
|
|
return $self->_get_xmetal();
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _create_document_from_string {
|
62
|
|
|
|
|
|
|
my ($self, $document_string) = @_;
|
63
|
|
|
|
|
|
|
my ($document);
|
64
|
|
|
|
|
|
|
eval {
|
65
|
|
|
|
|
|
|
my $documents = $self->_get_documents();
|
66
|
|
|
|
|
|
|
$document = $documents->OpenString($document_string);
|
67
|
|
|
|
|
|
|
$self->_die_on_ole_error();
|
68
|
|
|
|
|
|
|
};
|
69
|
|
|
|
|
|
|
croak $@ if $@; |
70
|
|
|
|
|
|
|
return $document;
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _create_document_from_path {
|
74
|
|
|
|
|
|
|
my ($self, $document_path) = @_;
|
75
|
|
|
|
|
|
|
my ($document);
|
76
|
|
|
|
|
|
|
eval {
|
77
|
|
|
|
|
|
|
my $documents = $self->_get_documents();
|
78
|
|
|
|
|
|
|
$document = $documents->Open($document_path, -1);
|
79
|
|
|
|
|
|
|
$self->_die_on_ole_error();
|
80
|
|
|
|
|
|
|
};
|
81
|
|
|
|
|
|
|
croak $@ if $@; |
82
|
|
|
|
|
|
|
return $document;
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub tear_down {
|
86
|
|
|
|
|
|
|
my ($self) = @_;
|
87
|
|
|
|
|
|
|
croak "Tear down method is not implemented yet."
|
88
|
|
|
|
|
|
|
#$self->_destroy_xmetal();
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _create_xmetal {
|
92
|
|
|
|
|
|
|
my ($self) = @_;
|
93
|
|
|
|
|
|
|
eval {
|
94
|
|
|
|
|
|
|
my $xmetal = Win32::OLE->new('XMetaL.Application', sub {$self->_destroy_xmetal()});
|
95
|
|
|
|
|
|
|
$self->_die_on_ole_error();
|
96
|
|
|
|
|
|
|
do {sleep 1} until $xmetal->InitComplete();
|
97
|
|
|
|
|
|
|
$self->_set_xmetal($xmetal);
|
98
|
|
|
|
|
|
|
};
|
99
|
|
|
|
|
|
|
die $@ if $@;
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _destroy_xmetal {
|
103
|
|
|
|
|
|
|
my ($self) = @_;
|
104
|
|
|
|
|
|
|
my $xmetal = $self->_get_xmetal();
|
105
|
|
|
|
|
|
|
eval {
|
106
|
|
|
|
|
|
|
undef $self->{_xmetal}; |
107
|
|
|
|
|
|
|
$xmetal->Quit(&XMETAL_NO_SAVE);
|
108
|
|
|
|
|
|
|
$self->_die_on_ole_error();
|
109
|
|
|
|
|
|
|
};
|
110
|
|
|
|
|
|
|
croak $@ if $@;
|
111
|
|
|
|
|
|
|
}
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _die_on_ole_error {
|
114
|
|
|
|
|
|
|
my ($self) = @_;
|
115
|
|
|
|
|
|
|
my $error = "".Win32::OLE->LastError();
|
116
|
|
|
|
|
|
|
die $error if $error;
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1;
|
120
|
|
|
|
|
|
|
__END__
|