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

Revision 171 (checked in by miyagawa, 14 years ago)
  • Added $entry->body_text, $entry->title_text and $feed->entry_text. Fixes #69
  • Added Plagger::Util utility class for functions like strip_html
  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Feed;
2 use strict;
3
4 use base qw( Class::Accessor::Fast );
5 __PACKAGE__->mk_accessors(qw( link url image description language author updated tags meta type ));
6
7 use Digest::MD5 qw(md5_hex);
8 use Plagger::Util;
9
10 sub new {
11     my $class = shift;
12     bless {
13         meta  => {},
14         tags  => [],
15         entries => [],
16         type  => 'feed',
17     }, $class;
18 }
19
20 sub add_entry {
21     my($self, $entry) = @_;
22     push @{ $self->{entries} }, $entry;
23 }
24
25 sub entries {
26     my $self = shift;
27     wantarray ? @{ $self->{entries} } : $self->{entries};
28 }
29
30 sub count {
31     my $self = shift;
32     scalar @{ $self->{entries} };
33 }
34
35 sub title {
36     my $self = shift;
37     if (@_) {
38         my $title = shift;
39         utf8::decode($title) unless utf8::is_utf8($title);
40         $self->{title} = $title;
41     }
42     $self->{title};
43 }
44
45 sub id {
46     my $self = shift;
47     $self->{id} = shift if @_;
48     $self->{id} || Digest::MD5::md5_hex($self->url || $self->link);
49 }
50
51 sub title_text {
52     my $self = shift;
53     Plagger::Util::strip_html($self->title);
54 }
55
56 1;
Note: See TracBrowser for help on using the browser.