| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyrights 2013-2014 by [Mark Overmeer]. |
|
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
|
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
|
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.01. |
|
5
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
55
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use strict; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
63
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Google::Merchant; |
|
9
|
2
|
|
|
2
|
|
9
|
use vars '$VERSION'; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
135
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.15'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
10
|
use Log::Report 'google-merchant'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
2840
|
use XML::Compile::Cache (); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use XML::LibXML (); |
|
17
|
|
|
|
|
|
|
use Google::Merchant::Util qw/:ns10/; |
|
18
|
|
|
|
|
|
|
use Scalar::Util qw/blessed/; |
|
19
|
|
|
|
|
|
|
use Encode qw/encode/; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $schemas; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new($%) { my $class = shift; (bless {}, $class)->init( {@_} ) } |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub init($) |
|
27
|
|
|
|
|
|
|
{ my ($self, $args) = @_; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
unless($schemas) |
|
30
|
|
|
|
|
|
|
{ $schemas = $self->_loadSchemas; |
|
31
|
|
|
|
|
|
|
$schemas->compileAll; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$self->{GM_feed} = {}; |
|
35
|
|
|
|
|
|
|
$self->{GM_string_format} = $args->{string_format} || 'HTML'; |
|
36
|
|
|
|
|
|
|
$self; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _loadSchemas() |
|
40
|
|
|
|
|
|
|
{ my $self = shift; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$schemas = XML::Compile::Cache->new |
|
43
|
|
|
|
|
|
|
( # prefixes must be kept short, to reduce transported file size |
|
44
|
|
|
|
|
|
|
prefixes => [g => NS_GOOGLE_BASE10, c => NS_GOOGLE_CUSTOM10] |
|
45
|
|
|
|
|
|
|
, any_element => 'TAKE_ALL' |
|
46
|
|
|
|
|
|
|
); |
|
47
|
|
|
|
|
|
|
$self->_loadXSD($schemas, 'google-base-10.xsd') |
|
48
|
|
|
|
|
|
|
->_loadXSD($schemas, 'google-base-10-bug.xsd'); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$schemas->declare(WRITER => 'g:item', hooks => |
|
51
|
|
|
|
|
|
|
[ { type => 'g:stringAttrValueType' |
|
52
|
|
|
|
|
|
|
, replace => sub {$self->_write_string(@_)} } |
|
53
|
|
|
|
|
|
|
] ); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$schemas; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _loadXSD($) |
|
59
|
|
|
|
|
|
|
{ my ($self, $schemas, $schema_fn) = @_; |
|
60
|
|
|
|
|
|
|
(my $fn = __FILE__) =~ s!([/\\])(\w+)\.pm$!$1$2$1xsd$1$schema_fn!; |
|
61
|
|
|
|
|
|
|
$schemas->importDefinitions($fn); |
|
62
|
|
|
|
|
|
|
$self; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#--------- |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub feed() {shift->{GM_feed}} |
|
68
|
|
|
|
|
|
|
sub schemas() {$schemas} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#--------- |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub stringFormat() { shift->{GM_string_format} } |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub addItem() {panic "not implemented"} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _baseItem($) |
|
78
|
|
|
|
|
|
|
{ my ($self, $google) = @_; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# more smart behavior may be required for the google base params |
|
81
|
|
|
|
|
|
|
$google; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#---------------- |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub write($%) |
|
87
|
|
|
|
|
|
|
{ my ($self, $fn, %args) = @_; |
|
88
|
|
|
|
|
|
|
$args{doc} ||= XML::LibXML::Document->new('1.0', 'UTF-8'); |
|
89
|
|
|
|
|
|
|
$args{feed} = $self->feed; |
|
90
|
|
|
|
|
|
|
$self->_write($fn, \%args); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _write($$) { panic "not implemented" } |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _write_base_entry($$) |
|
96
|
|
|
|
|
|
|
{ my ($self, $doc, $base) = @_; |
|
97
|
|
|
|
|
|
|
$self->schemas->writer('g:item')->($doc, $base); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _write_string($$$$$) |
|
101
|
|
|
|
|
|
|
{ my ($self, $doc, $val, $path, $tag, $r) = @_; |
|
102
|
|
|
|
|
|
|
return $val if blessed $val && $val->isa('XML::LibXML::Element'); |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $type; |
|
105
|
|
|
|
|
|
|
if(ref $val eq 'HASH') |
|
106
|
|
|
|
|
|
|
{ $type = $val->{type}; |
|
107
|
|
|
|
|
|
|
$val = $val->{_}; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
else |
|
110
|
|
|
|
|
|
|
{ $type = $self->stringFormat; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $str = encode 'utf8', $val; |
|
114
|
|
|
|
|
|
|
$str = XML::LibXML::CDATASection->new($str) |
|
115
|
|
|
|
|
|
|
if $type ne 'TEXT' && $str =~ m/\&/; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$r->($doc, $str); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
#------------ |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |