📄 feed.pm
字号:
}=head2 $feed->late_breaking_newsReturns an array or the number of elements (based on context) of the B<latest> L<XML::RSS::Headline> objects.=cutsub late_breaking_news { my ($self) = @_; my @list = grep { !$self->seen_headline( $_->id ); } @{ $self->{rss_headlines} }; return wantarray ? @list : scalar @list;}=head2 $feed->cacheIf tmpdir is defined the rss info is cached.=cutsub cache { my ($self) = @_; return unless $self->tmpdir; if ( -d $self->tmpdir && $self->num_headlines ) { my $tmp_filename = $self->tmpdir . '/' . $self->{name} . ".sto"; eval { store( $self->_build_dump_structure, $tmp_filename ) }; if ($@) { warn "[$self->{name}] Could not cache RSS XML to $tmp_filename\n"; return; } else { warn "[$self->{name}] Cached RSS Storable to $tmp_filename\n" if $self->{debug}; return 1; } } return;}sub _build_dump_structure { my ($self) = @_; my $cached = {}; $cached->{title} = $self->title; $cached->{link} = $self->link; $cached->{last_updated} = $self->{timestamp_hires}; $cached->{items} = []; for my $headline ( $self->headlines ) { push @{ $cached->{items} }, { headline => $headline->headline, url => $headline->url, description => $headline->description, first_seen => $headline->first_seen_hires, }; } return $cached;}=head2 $feed->set_last_updated=head2 $feed->set_last_updated( Time::HiRes::time )Set the time of when the feed was last processed. If you pass in a valueit will be used otherwise calls Time::HiRes::time.=cutsub set_last_updated { my ( $self, $hires_time ) = @_; $self->{hires_timestamp} = $hires_time if $hires_time; $self->{hires_timestamp} = Time::HiRes::time() unless $self->{hires_timestamp};}=head2 $feed->last_updatedThe time (in epoch seconds) of when the feed was last processed.=cutsub last_updated { my ($self) = @_; return int $self->{hires_timestamp};}=head2 $feed->last_updated_hiresThe time (in epoch seconds and milliseconds) of when the feed was last processed.=cutsub last_updated_hires { my ($self) = @_; return $self->{hires_timestamp};}=head1 SET/GET ACCESSOR METHODS=head2 $feed->title=head2 $feed->title( $title )The title of the RSS feed.=cutsub title { my ( $self, $title ) = @_; if ($title) { $title = _strip_whitespace($title); $self->{title} = $title if $title; } $self->{title};}=head2 $feed->debug=head2 $feed->debug( $bool )Turn on debugging messages=cutsub debug { my $self = shift @_; $self->{debug} = shift if @_; $self->{debug};}=head2 $feed->init=head2 $feed->init( $bool )init is used so that we just load the current headlines and don't return all headlines. in other words we initialize them. Takes a boolean argument.=cutsub init { my $self = shift @_; $self->{init} = shift if @_; $self->{init};}=head2 $feed->name=head2 $feed->name( $name )The identifier of an RSS feed.=cutsub name { my $self = shift; $self->{name} = shift if @_; $self->{name};}=head2 $feed->delay=head2 $feed->delay( $seconds )Number of seconds between updates.=cutsub delay { my $self = shift @_; $self->{delay} = shift if @_; $self->{delay};}=head2 $feed->link=head2 $feed->link( $rss_channel_url )The url in the RSS feed with a link back to the site where the RSS feed came from.=cutsub link { my $self = shift @_; $self->{link} = shift if @_; $self->{link};}=head2 $feed->url=head2 $feed->url( $url )The url in the RSS feed with a link back to the site where the RSS feed came from.=cutsub url { my $self = shift @_; $self->{url} = shift if @_; $self->{url};}=head2 $feed->headline_as_id=head2 $feed->headline_as_id( $bool )Within some RSS feeds the URL may not always be unique, in these casesyou can use the headline as the unique id. The id is used to check whetheror not a feed is new or has already been seen.=cutsub headline_as_id { my ( $self, $bool ) = @_; if ( defined $bool ) { $self->{headline_as_id} = $bool; $_->headline_as_id($bool) for $self->headlines; } $self->{headline_as_id};}=head2 $feed->hlobj=head2 $feed->hlobj( $class )Ablity to use a subclass of L<XML::RSS::Headline>. (See Perl Jobs example in L<XML::RSS::Headline::PerlJobs>). This should just be the name of the subclass.=cutsub hlobj { my ( $self, $hlobj ) = @_; $self->{hlobj} = $hlobj if defined $hlobj; $self->{hlobj};}=head2 $feed->tmpdir=head2 $feed->tmpdir( $tmpdir )Temporay directory to store cached RSS XML between instances for persistance.=cutsub tmpdir { my $self = shift @_; $self->{tmpdir} = shift if @_; $self->{tmpdir};}=head2 $feed->max_headlines=head2 $feed->max_headlines( $integer )The maximum number of headlines you'd like to keep track of. (0 means infinate)=cutsub max_headlines { my $self = shift @_; $self->{max_headlines} = shift if @_; $self->{max_headlines};}=head1 DEPRECATED METHODS=head2 $feed->failed_to_fetchThis should was deprecated because, the object shouldn't really knowanything about fetching, it just processes the results. This method currently will always return false=cutsub failed_to_fetch { warn __PACKAGE__ . "::failed_to_fetch has been deprecated"; return;}=head2 $feed->failed_to_parseThis method was deprecated because, $feed->parse now returns a bool value.This method will always return false=cutsub failed_to_parse { warn __PACKAGE__ . "::failed_to_parse has been deprecated"; return;}=head1 AUTHORJeff Bisbee, C<< <jbisbee at cpan.org> >>=head1 BUGSPlease report any bugs or feature requests toC<bug-xml-rss-feed at rt.cpan.org>, or through the web interface atL<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-RSS-Feed>.I will be notified, and then you'll automatically be notified of progress onyour bug as I make changes.=head1 SUPPORTYou can find documentation for this module with the perldoc command. perldoc XML::RSS::FeedYou can also look for information at:=over 4=item * AnnoCPAN: Annotated CPAN documentationL<http://annocpan.org/dist/XML-RSS-Feed>=item * CPAN RatingsL<http://cpanratings.perl.org/d/XML-RSS-Feed>=item * RT: CPAN's request trackerL<http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-RSS-Feed>=item * Search CPANL<http://search.cpan.org/dist/XML-RSS-Feed>=back=head1 ACKNOWLEDGEMENTSSpecial thanks to Rocco Caputo, Martijn van Beers, Sean Burke, Prakash Kailasaand Randal Schwartz for their help, guidance, patience, and bug reports. Guys thanks for actually taking time to use the code and give good, honest feedback.=head1 COPYRIGHT & LICENSECopyright 2006 Jeff Bisbee, all rights reserved.This program is free software; you can redistribute it and/or modify itunder the same terms as Perl itself.=head1 SEE ALSOL<XML::RSS::Headline>, L<XML::RSS::Headline::PerlJobs>, L<XML::RSS::Headline::Fark>, L<XML::RSS::Headline::UsePerlJournals>, L<POE::Component::RSSAggregator>=cut1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -