| 1 | package Dancer::Plugin::XML::RSS; | ||
| 2 | |||
| 3 | 1 | ▶ | use Dancer ':syntax'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Dancer::Plugin; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 0 | ▶ | use XML::RSS; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | |||
| 8 | our $VERSION = '0.01'; | ||
| 9 | |||
| 10 | register 'rss' => sub { | ||
| 11 | my $option = shift; # 'new' force creation of new obj | ||
| 12 | my $settings = plugin_setting || {}; | ||
| 13 | |||
| 14 | debug( $settings ); | ||
| 15 | |||
| 16 | # need to lookup format for plugin setting and see if this will map to | ||
| 17 | # values correct in xml::rss object | ||
| 18 | var xml_rss_obj => ( | ||
| 19 | ! vars->{xml_rss_obj} || ( defined $option && $option =~ /new/i ) ? | ||
| 20 | XML::RSS->new( %{ $settings } ) : vars->{xml_rss_obj} ); | ||
| 21 | |||
| 22 | return vars->{xml_rss_obj}; | ||
| 23 | }; | ||
| 24 | |||
| 25 | register 'rss_output' => sub { | ||
| 26 | content_type('text/xml'); # or application/xml+rss? | ||
| 27 | return vars->{xml_rss_obj}->as_string; | ||
| 28 | }; | ||
| 29 | |||
| 30 | register_plugin; | ||
| 31 | |||
| 32 | =head1 NAME | ||
| 33 | |||
| 34 | Dancer::Plugin::XML::RSS - Dancer plugin for using XML::RSS to parse or create RSS feeds | ||
| 35 | |||
| 36 | =head1 VERSION | ||
| 37 | |||
| 38 | Version 0.01 | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | =head1 SYNOPSIS | ||
| 43 | |||
| 44 | Allows access to XML::RSS object from inside of your Dancer application and | ||
| 45 | default configuration of XML::RSS using the standard Dancer configuration file. | ||
| 46 | |||
| 47 | package MyDancerApp; | ||
| 48 | |||
| 49 | use Dancer 'syntax'; | ||
| 50 | use Dancer::Plugin::XML::RSS; | ||
| 51 | |||
| 52 | # parse rss file and output | ||
| 53 | get '/show_news' => { | ||
| 54 | rss->parsefile( settings( 'news_feed' ) ); | ||
| 55 | |||
| 56 | # grab entries for template | ||
| 57 | my @stories; | ||
| 58 | my $display_max = settings('news_feed_display') || 5; | ||
| 59 | |||
| 60 | for ( my $i = 0; $i <= $display_max; $i++ ) { | ||
| 61 | next unless exists rss->{items}->[$i] | ||
| 62 | and ref rss->{items}; | ||
| 63 | |||
| 64 | push @stories, $item; | ||
| 65 | } | ||
| 66 | |||
| 67 | template 'news', { stories => \@stories }; | ||
| 68 | }; | ||
| 69 | |||
| 70 | get '/our_feed' => { | ||
| 71 | rss->channel( | ||
| 72 | title => 'My Special Site', | ||
| 73 | link => 'mysite.example.org', | ||
| 74 | description => 'A generic example for docs', | ||
| 75 | ); | ||
| 76 | |||
| 77 | rss->add_item( | ||
| 78 | ); | ||
| 79 | |||
| 80 | rss_output; | ||
| 81 | }; | ||
| 82 | |||
| 83 | =head1 DESCRIPTION | ||
| 84 | |||
| 85 | Provides a simple way to parse RSS files by using C<XML::RSS>. It will hold onto currently | ||
| 86 | parsed feed or keyword 'rss' will return object instance for application use. | ||
| 87 | |||
| 88 | Using the 'rss_output' command it will first create correct content type and then | ||
| 89 | serialize object into RSS XML for use in route. | ||
| 90 | |||
| 91 | =head1 CONFIGURATION | ||
| 92 | |||
| 93 | XML:RSS configuration parameters will be taken from your C<Dancer> application config file. They should be specified as: | ||
| 94 | |||
| 95 | plugins: | ||
| 96 | 'XML::RSS': | ||
| 97 | output: '0.9' # output as rss v0.9 | ||
| 98 | |||
| 99 | See C<XML::RSS> for more detail on configuration options. | ||
| 100 | |||
| 101 | |||
| 102 | =head1 SUBROUTINES/METHODS | ||
| 103 | |||
| 104 | =head2 rss('new') | ||
| 105 | |||
| 106 | Creates and returns XML::RSS object. It will be setup with any XML::RSS options from configuration file. | ||
| 107 | |||
| 108 | After first call to rss existing XML::RSS object will be called to force a new object pass | ||
| 109 | 'new' to C<rss> | ||
| 110 | |||
| 111 | =over | ||
| 112 | |||
| 113 | =item 'new' - optional string to force creation of new rss object | ||
| 114 | |||
| 115 | =back | ||
| 116 | |||
| 117 | =cut | ||
| 118 | |||
| 119 | =head2 rss_output | ||
| 120 | |||
| 121 | Converts XML::RSS object into xml with correct content type and body. Use for returning inside of route. | ||
| 122 | |||
| 123 | =head1 AUTHOR | ||
| 124 | |||
| 125 | Lee Carmichael, C<< <lcarmich at cpan.org> >> | ||
| 126 | |||
| 127 | =head1 BUGS | ||
| 128 | |||
| 129 | Please report any bugs or feature requests to C<bug-dancer-plugin-xml-rss at rt.cpan.org>, or through | ||
| 130 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-XML-RSS>. I will be notified, and then you'll | ||
| 131 | automatically be notified of progress on your bug as I make changes. | ||
| 132 | |||
| 133 | =head1 SUPPORT | ||
| 134 | |||
| 135 | You can find documentation for this module with the perldoc command. | ||
| 136 | |||
| 137 | perldoc Dancer::Plugin::XML::RSS | ||
| 138 | |||
| 139 | |||
| 140 | You can also look for information at: | ||
| 141 | |||
| 142 | =over 4 | ||
| 143 | |||
| 144 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 145 | |||
| 146 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-XML-RSS> | ||
| 147 | |||
| 148 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 149 | |||
| 150 | L<http://annocpan.org/dist/Dancer-Plugin-XML-RSS> | ||
| 151 | |||
| 152 | =item * CPAN Ratings | ||
| 153 | |||
| 154 | L<http://cpanratings.perl.org/d/Dancer-Plugin-XML-RSS> | ||
| 155 | |||
| 156 | =item * Search CPAN | ||
| 157 | |||
| 158 | L<http://search.cpan.org/dist/Dancer-Plugin-XML-RSS/> | ||
| 159 | |||
| 160 | =back | ||
| 161 | |||
| 162 | =head1 TODO | ||
| 163 | |||
| 164 | =over 4 | ||
| 165 | |||
| 166 | =item * Add configuration of output header with config file | ||
| 167 | |||
| 168 | =item * Use configuration file to setup details of channel for rss output | ||
| 169 | |||
| 170 | =back | ||
| 171 | |||
| 172 | =head1 LICENSE AND COPYRIGHT | ||
| 173 | |||
| 174 | Copyright 2011 Lee Carmichael. | ||
| 175 | |||
| 176 | This program is free software; you can redistribute it and/or modify it | ||
| 177 | under the terms of either: the GNU General Public License as published | ||
| 178 | by the Free Software Foundation; or the Artistic License. | ||
| 179 | |||
| 180 | See http://dev.perl.org/licenses/ for more information. | ||
| 181 | |||
| 182 | =head1 SEE ALSO | ||
| 183 | |||
| 184 | C<Dancer>, C<XML::RSS>, C<Dancer::Plugin>, C<Dancer::Plugin::Feed> | ||
| 185 | |||
| 186 | =cut | ||
| 187 | |||
| 188 | 1; # End of Dancer::Plugin::XML::RSS | ||