line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::2ch; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27451
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
348
|
use UNIVERSAL::require; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use base qw( Class::Accessor::Fast ); |
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw( conf worker cache ua setting subject) ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use WWW::2ch::Setting; |
12
|
|
|
|
|
|
|
use WWW::2ch::Subject; |
13
|
|
|
|
|
|
|
use WWW::2ch::Dat; |
14
|
|
|
|
|
|
|
use WWW::2ch::UserAgent; |
15
|
|
|
|
|
|
|
use WWW::2ch::Cache; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
|
|
|
|
|
|
my ($class, %conf) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $self = bless {}, $class; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$self->{plugin} = $conf{plugin} || 'Base'; |
23
|
|
|
|
|
|
|
$self->load_plugin; |
24
|
|
|
|
|
|
|
$self->conf($self->worker->gen_conf(\%conf)); |
25
|
|
|
|
|
|
|
$self->ua( WWW::2ch::UserAgent->new($conf{ua}) ); |
26
|
|
|
|
|
|
|
$self->cache( WWW::2ch::Cache->new($conf{cache}) ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub load_plugin { |
32
|
|
|
|
|
|
|
my ($self, $conf) = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $module; |
35
|
|
|
|
|
|
|
if (-f $self->{plugin}) { |
36
|
|
|
|
|
|
|
open my $fh, $self->{plugin} or return; |
37
|
|
|
|
|
|
|
while (<$fh>) { |
38
|
|
|
|
|
|
|
if (/^package (WWW::2ch::Plugin::.*?);/) { |
39
|
|
|
|
|
|
|
eval { require $self->{plugin} } or die $@; |
40
|
|
|
|
|
|
|
$module = $1; |
41
|
|
|
|
|
|
|
last; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} else { |
45
|
|
|
|
|
|
|
$module = $self->{plugin}; |
46
|
|
|
|
|
|
|
$module =~ s/^WWW::2ch::Plugin:://;; |
47
|
|
|
|
|
|
|
$module = "WWW::2ch::Plugin::$module"; |
48
|
|
|
|
|
|
|
$module->require or die $@; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
$self->worker($module->new($self->conf)); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub encoding { $_[0]->worker->encoding } |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub load_setting { |
56
|
|
|
|
|
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return unless $self->conf->{setting}; |
59
|
|
|
|
|
|
|
$self->setting( WWW::2ch::Setting->new($self, $self->conf->{setting}) )->load; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub load_subject { |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return unless $self->conf->{subject}; |
66
|
|
|
|
|
|
|
$self->subject( WWW::2ch::Subject->new($self, $self->conf->{subject}) )->load; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub parse_dat { |
70
|
|
|
|
|
|
|
my ($self, $data, $subject) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$subject = { $subject } unless ref($subject); |
73
|
|
|
|
|
|
|
my $dat = WWW::2ch::Dat->new($self, $subject); |
74
|
|
|
|
|
|
|
$dat->dat($data); |
75
|
|
|
|
|
|
|
$dat->parse; |
76
|
|
|
|
|
|
|
$dat; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub recall_dat { |
80
|
|
|
|
|
|
|
my ($self, $key) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $dat = WWW::2ch::Dat->new($self, {}); |
83
|
|
|
|
|
|
|
$dat->key($key); |
84
|
|
|
|
|
|
|
$dat->get_cache; |
85
|
|
|
|
|
|
|
$dat->parse; |
86
|
|
|
|
|
|
|
$dat; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |