root/trunk/plagger/lib/Plagger/Thing.pm

Revision 1024 (checked in by miyagawa, 14 years ago)
  • Add mk_date_accessors to Entry and Feed
  • Now CustomFeed?::Debug can set datetime
  • Make clone of config if it's a hash ref
  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Thing;
2 use strict;
3 use base qw( Class::Accessor::Fast );
4
5 sub has_tag {
6     my($self, $want_tag) = @_;
7     for my $tag (@{$self->tags}) {
8         return 1 if $tag eq $want_tag;
9     }
10     return 0;
11 }
12
13 sub add_tag {
14     my($self, $tag) = @_;
15     push @{$self->tags}, $tag
16         unless $self->has_tag($tag);
17 }
18
19 sub clone {
20     my $self = shift;
21     my $clone = Storable::dclone($self);
22     $clone;
23 }
24
25 sub mk_date_accessors {
26     my $class = shift;
27
28     for my $key (@_) {
29         no strict 'refs';
30         *{"$class\::$key"} = sub {
31             my $obj = shift;
32             if (@_) {
33                 my $date = $_[0];
34                 unless (ref($date)) {
35                     $date = Plagger::Date->parse_dwim($date);
36                 }
37                 $obj->{$key} = $date;
38             } else {
39                 return $obj->{$key};
40             }
41         };
42     }
43 }
44
45 1;
Note: See TracBrowser for help on using the browser.