1package Net::Google::Calendar::FeedLink; 2 3use strict; 4use XML::Atom::Feed; 5use XML::Atom::Link; 6use base qw(XML::Atom::Link Net::Google::Calendar::Base); 7use LWP::Simple qw(get); 8 9=head1 NAME 10 11Net::Google::Calendar::FeedLink - represents a link to a feed 12 13=head1 SYNOPSIS 14 15 my @feeds = $comments->feeds; 16 17 foreach my $feed (@feeds) { 18 print "There are ".$feed->count_hint." comments in this feed\n"; 19 print "Is this feed read only? ".$feed->read_only."\n"; 20 print "This feed ".(($feed->href)? "is" : "isn't" )." remote\n"; 21 print "This feed is of type ".$feed->rel."\n"; 22 23 my $atom = $cal->get_feed($feed->feed); # $obj is an XML::Atom::Feed 24 foreach my $comment ($atom->entries) { 25 print "\t".$comment->title."\n"; 26 } 27 } 28 29=head1 METHODS 30 31=cut 32 33=head2 new 34 35Create a new FeedLink 36 37=cut 38 39sub new { 40 my $class = shift; 41 return $class->SUPER::new(@_); 42} 43 44=head2 count_hint 45 46Hints at the number of entries in the feed. 47Depending on the implementation, may not be a precise count. 48 49=cut 50 51sub count_hint { 52 my $self = shift; 53 return $self->_do('@countHint', @_); 54} 55 56=head2 element_name 57 58Return our Element name 59 60=cut 61 62sub element_name { 63 return 'gd:feedLink'; 64} 65 66=head2 read_only [boolean] 67 68Specifies whether the contained feed is read-only. 69 70=cut 71 72sub read_only { 73 my $self = shift; 74 if (@_) { 75 my $val = @_; 76 push @_, ($val)? 'true' : 'false'; 77 } 78 return _convert_bool($self->_do('@readOnly', @_)); 79} 80 81sub _convert_bool { 82 my $val = shift; 83 return '' if !defined $val; 84 return $val if ($val =~ m!^(\d+)$! && ($val==0 or $val==1)); 85 return 0 if $val eq 'false'; 86 return 1 if $val eq 'true'; 87 #die "Illegal boolean value $val"; 88 return ($val)? 1 : 0; 89} 90 91=head2 rel [rel] 92 93Specifies the link relation; allows the service to provide 94multiple types of feed links for a single entity. Has the 95same semantics and allowed values as the rel attribute of 96the <atom:link> element. 97 98=cut 99 100sub rel { 101 my $self = shift; 102 return $self->_do('@rel', @_); 103} 104 105 106=head2 href [url] 107 108Specifies the feed URI. If the nested feed is embedded and not 109linked, this attribute may be omitted. 110 111=cut 112 113sub href { 114 my $self = shift; 115 return URI->new($self->_do('@href')); 116} 117 118 119sub _do { 120 my $self = shift; 121 my $name = shift; 122 my $attr = ($name =~ s!^@!!); 123 my $gd_ns = ''; # $self->{_gd_ns}; 124 if (@_) { 125 my $new = shift; 126 if ($attr) { 127 $self->set_attr($name, $new); 128 } else { 129 $self->set($gd_ns, "${name}", '', { value => "${new}" }); 130 } 131 } 132 my $val; 133 if ($attr) { 134 $val = $self->get_attr($name); 135 } else { 136 $val = $self->_my_get($gd_ns, "${name}"); 137 } 138 return $val; 139} 140 141=head2 feed [feed] 142 143Get the Atom feed. 144 145Returns a URI object if the feed is remote 146or a scalar containing an XML::Atom::Feed object 147 148=cut 149 150sub feed { 151 my $self = shift; 152 my $ns = ""; # "http://purl.org/atom/ns#"; 153 if (@_) { 154 my $feed = shift; 155 XML::Atom::Base::set($self, $ns, 'feed', $feed, {}); 156 #$self->add($ns, 'feed', $feed, {}); 157 } 158 my $href = $self->href; 159 if (defined $href) { 160 return URI->new($href); 161 } else { 162 my $feed = $self->_do('feed') || return; 163 my $tmp = XML::Atom::Feed->new( Elem => $feed ); 164 $tmp->{ns} = $ns; 165 return $tmp; 166 } 167} 1681; 169