| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MojoMojo::Formatter::Amazon; |
|
2
|
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
12102
|
eval "use Net::Amazon"; |
|
|
27
|
|
|
|
|
1337339
|
|
|
|
27
|
|
|
|
|
384
|
|
|
4
|
|
|
|
|
|
|
my $eval_res=$@; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head2 module_loaded |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Return true if the module is loaded. |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
|
11
|
|
|
|
|
|
|
|
|
12
|
125
|
50
|
|
125
|
1
|
792
|
sub module_loaded { $eval_res ? 0 : 1 } |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION='0.01'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
MojoMojo::Formatter::Amazon - Include Amazon objects on your page. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This is an url formatter. it takes urls containing amazon and |
|
24
|
|
|
|
|
|
|
/-/ or /ASIN/ and make a pretty formatted link to that object |
|
25
|
|
|
|
|
|
|
in the amazon web store. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
It automatically handles books/movies/dvds and formats them as |
|
28
|
|
|
|
|
|
|
apropriate. You can also pass 'small' as a parameter after the |
|
29
|
|
|
|
|
|
|
url, and it will make a thumb link instead of a blurb. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 format_content_order |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Format order can be 1-99. The Amazon formatter runs on 5. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
|
38
|
|
|
|
|
|
|
|
|
39
|
744
|
|
|
744
|
1
|
2904905
|
sub format_content_order { 5 } |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 format_content |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
calls the formatter. Takes a ref to the content as well as the |
|
44
|
|
|
|
|
|
|
context object. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub format_content { |
|
49
|
124
|
|
|
124
|
1
|
844
|
my ($class,$content,$c)=@_; |
|
50
|
124
|
50
|
|
|
|
561
|
return unless $class->module_loaded; |
|
51
|
124
|
|
|
|
|
870
|
my @lines=split /\n/,$$content; |
|
52
|
124
|
|
|
|
|
313
|
my $pod;$$content=""; |
|
|
124
|
|
|
|
|
340
|
|
|
53
|
124
|
|
|
|
|
380
|
foreach my $line (@lines) { |
|
54
|
648
|
50
|
|
|
|
1448
|
if ($line =~ m/(\{\{?:http:\/\/(?:www\.){0,1}amazon\.com(?:\/.*){0,1}(?:\/dp\/|\/gp\/product\/))(.*?)(?:\/.*|$)\}\}/) { |
|
55
|
0
|
|
|
|
|
0
|
my $item=$class->get($1,$c->config->{amazon_id}); |
|
56
|
0
|
0
|
|
|
|
0
|
unless (ref($item)) { |
|
57
|
0
|
|
|
|
|
0
|
$$content.=$line."\n"; |
|
58
|
0
|
|
|
|
|
0
|
next; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
0
|
0
|
|
|
|
0
|
if ($2) { |
|
61
|
0
|
0
|
|
|
|
0
|
next unless $class->can($2); |
|
62
|
0
|
|
|
|
|
0
|
$$content.=$class->$2($item); |
|
63
|
|
|
|
|
|
|
} else { |
|
64
|
0
|
|
|
|
|
0
|
$$content.=$class->blurb($item); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} else { |
|
67
|
648
|
|
|
|
|
1641
|
$$content .=$line."\n"; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 get <asin> |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Connects to amazon and retrieves a L<Net::Amazon> object |
|
76
|
|
|
|
|
|
|
based on the supplied ASIN number. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub get { |
|
81
|
0
|
|
|
0
|
1
|
|
my ($class,$id,$amazon_id,$secret_key)=@_; |
|
82
|
|
|
|
|
|
|
#FIXME: devel token should be set in formatter config. |
|
83
|
0
|
|
|
|
|
|
my $amazon=Net::Amazon->new(token=>$amazon_id,secret_key=>$secret_key); |
|
84
|
0
|
|
|
|
|
|
my $response=$amazon->search(asin=>$id); |
|
85
|
0
|
0
|
|
|
|
|
return "Unable to connect to amazon." unless $response->is_success; |
|
86
|
0
|
|
|
|
|
|
($property)=$response->properties; |
|
87
|
0
|
0
|
|
|
|
|
return "No property object" unless $property; |
|
88
|
0
|
|
|
|
|
|
return $property; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 small <property> |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Renders a small version of the formatter. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub small { |
|
98
|
0
|
|
|
0
|
1
|
|
my ($class,$property)=@_; |
|
99
|
0
|
|
|
|
|
|
return "!".$property->ImageUrlMedium. |
|
100
|
|
|
|
|
|
|
'!:http://www.amazon.com/exec/obidos/ASIN/'.$property->Asin."/feed-20\n"; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 blurb <property> |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
renders a full width blurb of the product, suitable for reviews and |
|
106
|
|
|
|
|
|
|
such. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub blurb { |
|
111
|
0
|
|
|
0
|
1
|
|
my ($class,$property)=@_; |
|
112
|
0
|
|
|
|
|
|
my $method=ref $property; |
|
113
|
0
|
|
|
|
|
|
$method =~ s/.*:://; |
|
114
|
0
|
|
0
|
|
|
|
return "<div class=\"amazon\">!<".$property->ImageUrlSmall. |
|
115
|
|
|
|
|
|
|
'!:http://www.amazon.com/exec/obidos/ASIN/'.$property->Asin."/feed-20\n\n". |
|
116
|
|
|
|
|
|
|
"h1. ".$property->ProductName."\n\n". |
|
117
|
|
|
|
|
|
|
'"buy at amazon for '.$property->OurPrice.'":'. |
|
118
|
|
|
|
|
|
|
'http://www.amazon.com/exec/obidos/ASIN/'.$property->Asin."/feed-20\n\n". |
|
119
|
|
|
|
|
|
|
($method && ($class->can($method) ? $class->$method($property) :"<br/>\n\n")). |
|
120
|
|
|
|
|
|
|
"</div>"; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 DVD <property> |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Product information suitable for DVD movies. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub DVD { |
|
130
|
0
|
|
|
0
|
1
|
|
my ($class,$property) = @_; |
|
131
|
0
|
|
|
|
|
|
return " -- ??".join(',',$property->directors).'?? ('.$property->year .")\n\n"; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 Book <property> |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Product information suitable for books. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub Book { |
|
141
|
0
|
|
|
0
|
1
|
|
my ($class,$property) = @_; |
|
142
|
0
|
|
|
|
|
|
return " -- ??".join(',',$property->authors).'?? ('.$property->year .")\n\n"; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 Music <property> |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Product information suitable for music CDs. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub Music { |
|
152
|
0
|
|
|
0
|
1
|
|
my ($class,$property) = @_; |
|
153
|
0
|
|
|
|
|
|
return " -- ??".join(',',$property->artists).'?? ('.$property->year .")\n\n"; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L<MojoMojo>, L<Module::Pluggable::Ordered>, L<Net::Amazon>. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHORS |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Marcus Ramberg <mramberg@cpan.org |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 LICENSE |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify |
|
167
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |