root/lang/perl/XML-Atom-Server-Lite/trunk/lib/XML/Atom/Server/Lite/Entry.pm @ 8595

Revision 8595, 2.8 kB (checked in by mattn, 7 years ago)

lang/perl/XML-Atom-Server-Lite/trunk/lib/XML/Atom/Server/Lite/Entry.pm,
lang/perl/XML-Atom-Server-Lite/trunk/lib/XML/Atom/Server/Lite/Feed.pm:
replace several tabs to spaces.

Line 
1# $Id$
2
3package XML::Atom::Server::Lite::Entry;
4use strict;
5use XML::Atom::Server::Lite qw/qquote encode_xml/;
6
7sub new {
8    my $class = shift;
9    my $self = bless {}, $class;
10    $self->{id} = '';
11    $self->{logo} = '';
12    $self->{icon} = '';
13    $self->{title} = '';
14    $self->{link} = [];
15    $self->{subject} = [];
16    $self->{author} = [];
17    $self->{content} = {};
18    $self->{category} = {};
19    $self;
20}
21
22sub title {
23    my $self = shift;
24    if (@_) { $self->{title} = $_[0] } else { $self->{title}||'' };
25}
26
27sub id {
28    my $self = shift;
29    if (@_) { $self->{id} = $_[0] } else { $self->{id}||'' };
30}
31
32sub logo {
33    my $self = shift;
34    if (@_) { $self->{logo} = $_[0] } else { $self->{logo}||'' };
35}
36
37sub icon {
38    logo(@_);
39}
40
41sub author {
42    my $self = shift;
43    if (@_) { $self->{author} = \@_ } else { $self->{author}||() };
44}
45
46sub link {
47    my $self = shift;
48    if (@_) {
49        if (ref($_[0]) eq 'ARRAY') {
50            $self->{link} = $_[0];
51        } else {
52            push @{$self->{link}}, $_[0];
53        }
54    } else { $self->{link}||(); };
55}
56
57sub subject {
58    my $self = shift;
59    if (@_) {
60        if (ref($_[0]) eq 'ARRAY') {
61            $self->{subject} = $_[0];
62        } else {
63            push @{$self->{subject}}, $_[0];
64        }
65    } else { $self->{subject}||(); };
66}
67
68sub category {
69    my $self = shift;
70    if (@_) { $self->{category} = $_[0] } else { $self->{category}||{} };
71}
72
73sub content {
74    my $self = shift;
75    if (@_) { $self->{content} = $_[0] } else { $self->{content}||{} };
76}
77
78sub to_xml {
79    my $self = shift;
80    my $xml = "";
81    $xml .= " <entry>\n";
82    for my $link (@{$self->{link}}) {
83        $xml .= "  <link"
84             .  " rel=".XML::Atom::Server::Lite::qquote($link->{rel})
85             .  " type=".XML::Atom::Server::Lite::qquote($link->{type})
86             .  " href=".XML::Atom::Server::Lite::qquote($link->{href})."/>\n";
87    }
88    $xml .= "  <title>"
89           . XML::Atom::Server::Lite::encode_xml($self->{title})
90           . "</title>\n" if $self->{title};
91    $xml .= "  <content"
92         .  " mode=".XML::Atom::Server::Lite::qquote($self->{content}->{mode})
93         .  " type=".XML::Atom::Server::Lite::qquote($self->{content}->{type}).">"
94         .  "<div xmlns=\"http://www.w3.org/1999/xhtml\">"
95         .  XML::Atom::Server::Lite::encode_xml($self->{content}->{body})
96         .  "</div></content>\n" if $self->{content};
97    $xml .= "  <category"
98            ." term=".XML::Atom::Server::Lite::qquote($self->{category}->{term})
99            ." label=".XML::Atom::Server::Lite::qquote($self->{category}->{label})."/>\n" if $self->{category};
100    for my $subject (@{$self->{subject}}) {
101        $xml .= "  <dc:subject>"
102               . XML::Atom::Server::Lite::encode_xml($subject)
103               . "</dc:subject>\n";
104    }
105    $xml .= " </entry>\n";
106}
107
1081;
Note: See TracBrowser for help on using the browser.