line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::KakakuCom; |
2
|
2
|
|
|
2
|
|
51936
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
86
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
71
|
|
4
|
2
|
|
|
2
|
|
13
|
use base qw/Class::Accessor::Fast Class::Data::Inheritable/; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
1959
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12841
|
use URI; |
|
2
|
|
|
|
|
18240
|
|
|
2
|
|
|
|
|
73
|
|
7
|
2
|
|
|
2
|
|
24
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
172
|
|
8
|
2
|
|
|
2
|
|
2610
|
use Readonly; |
|
2
|
|
|
|
|
9290
|
|
|
2
|
|
|
|
|
179
|
|
9
|
2
|
|
|
2
|
|
2606
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
93798
|
|
|
2
|
|
|
|
|
76
|
|
10
|
2
|
|
|
2
|
|
1936
|
use Jcode; |
|
2
|
|
|
|
|
209085
|
|
|
2
|
|
|
|
|
258
|
|
11
|
2
|
|
|
2
|
|
1493
|
use WebService::KakakuCom::Parser; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Data::Page; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly my $ApiRoot => 'http://api.kakaku.com/Ver1/'; |
15
|
|
|
|
|
|
|
Readonly my $EntriesPerPage => 5; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = 0.05; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ie/); |
20
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata($_) for qw/debug/; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub ua { |
23
|
|
|
|
|
|
|
my $self = shift; |
24
|
|
|
|
|
|
|
if (@_) { |
25
|
|
|
|
|
|
|
$self->{ua} = shift; |
26
|
|
|
|
|
|
|
} else { |
27
|
|
|
|
|
|
|
$self->{ua} and return $self->{ua}; |
28
|
|
|
|
|
|
|
$self->{ua} = LWP::UserAgent->new; |
29
|
|
|
|
|
|
|
$self->{ua}->agent(join '/', __PACKAGE__, $self->VERSION); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
$self->{ua}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub search { |
35
|
|
|
|
|
|
|
my ($self, $keyword, $args) = @_; |
36
|
|
|
|
|
|
|
defined $keyword or croak "No keyword was given"; |
37
|
|
|
|
|
|
|
$args ||= {}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $uri = URI->new_abs('ItemSearch.asp', $ApiRoot); |
40
|
|
|
|
|
|
|
$uri->query_form( |
41
|
|
|
|
|
|
|
Keyword => Jcode->new($keyword, $self->ie)->sjis, |
42
|
|
|
|
|
|
|
CategoryGroup => $args->{CategoryGroup} || 'ALL', |
43
|
|
|
|
|
|
|
ResultSet => $args->{ResultSet} || 'medium', |
44
|
|
|
|
|
|
|
SortOrder => $args->{SortOrder} || '', |
45
|
|
|
|
|
|
|
PageNum => $args->{PageNum} || 1, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $res = $self->ua->get($uri); |
49
|
|
|
|
|
|
|
croak $res->status_line if $res->is_error; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $rs = WebService::KakakuCom::Parser->parse_for_search($res->content); |
52
|
|
|
|
|
|
|
$rs->pager(Data::Page->new($rs->NumOfResult, $EntriesPerPage, $args->{PageNum} || 1)); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
wantarray ? @$rs : $rs; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub product { |
58
|
|
|
|
|
|
|
my ($self, $product_id, $args) = @_; |
59
|
|
|
|
|
|
|
defined $product_id or croak "No ProductID was given"; |
60
|
|
|
|
|
|
|
$args ||= {}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $uri = URI->new_abs('ItemInfo.ashx', $ApiRoot); |
63
|
|
|
|
|
|
|
$uri->query_form( |
64
|
|
|
|
|
|
|
ProductID => $product_id, |
65
|
|
|
|
|
|
|
ResultSet => $args->{ResultSet} || 'medium' |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $res = $self->ua->get($uri); |
69
|
|
|
|
|
|
|
croak $res->status_line if $res->is_error; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
WebService::KakakuCom::Parser->parse_for_product($res->content); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |