| 1 | package WWW::2ch::Setting; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | use base qw( Class::Accessor::Fast ); | ||
| 5 | __PACKAGE__->mk_accessors( qw( c url config title noname image) ); | ||
| 6 | |||
| 7 | |||
| 8 | sub new { | ||
| 9 | my $class = shift; | ||
| 10 | my $c = shift; | ||
| 11 | my $url = shift; | ||
| 12 | |||
| 13 | my $self = bless {c => $c, url => $url}, $class; | ||
| 14 | |||
| 15 | $self; | ||
| 16 | } | ||
| 17 | |||
| 18 | sub load { | ||
| 19 | my $self = shift; | ||
| 20 | |||
| 21 | return 0 unless $self->c && $self->url; | ||
| 22 | my $res = $self->c->ua->get($self->url); | ||
| 23 | return 0 unless $res->is_success; | ||
| 24 | |||
| 25 | my $config = $self->c->worker->parse_setting($res->content); | ||
| 26 | $self->config($config); | ||
| 27 | $self->title($config->{title}); | ||
| 28 | $self->noname($config->{noname}); | ||
| 29 | $self->image($config->{image}); | ||
| 30 | |||
| 31 | return 1; | ||
| 32 | } | ||
| 33 | |||
| 34 | 1; |