diff --git a/lib/Dancer/Plugin/Feed.pm b/lib/Dancer2/Plugin/Feed.pm similarity index 82% rename from lib/Dancer/Plugin/Feed.pm rename to lib/Dancer2/Plugin/Feed.pm index 1b3b285..ff0af56 100644 --- a/lib/Dancer/Plugin/Feed.pm +++ b/lib/Dancer2/Plugin/Feed.pm @@ -1,24 +1,16 @@ -package Dancer::Plugin::Feed; +package Dancer2::Plugin::Feed; -use Dancer ':syntax'; -use Dancer::Plugin; -use Dancer::Exception qw(:all); +use Dancer2 ':syntax'; +use Dancer2::Plugin; use XML::Feed; -#ABSTRACT: Easy to generate feed rss or atom for Dancer applications. +#ABSTRACT: Easy to generate feed rss or atom for Dancer2 applications. my $ct = { atom => 'application/atom+xml', rss => 'application/rss+xml', }; -#Register exception -register_exception('FeedInvalidFormat', - message_pattern => "Unknown format use rss or atom: %s" -); -register_exception('FeedNoFormat', - message_pattern => "Format is missing" -); my @feed_properties = qw/format title base link tagline description author id language copyright self_link modified/; @@ -27,7 +19,7 @@ my @entries_properties = qw/title base link content summary category tags author id issued modified enclosure/; register create_feed => sub { - my ($dsl, %params) = plugin_args(@_); + my ($dsl, %params) = @_; my $format = _validate_format(\%params); @@ -36,7 +28,7 @@ register create_feed => sub { }elsif($format =~/^rss$/i) { _create_rss_feed(\%params); }else{ - raise FeedInvalidFormat => $format; + die "Unknown format $format, use rss or atom\n"; } }; @@ -53,16 +45,17 @@ register create_rss_feed => sub { }; sub _validate_format { - my $params = shift; + my( $params, $dsl ) = @_; my $format = delete $params->{format}; if (!$format) { my $settings = plugin_setting; - $format = $settings->{format} or raise 'FeedNoFormat'; + $format = $settings->{format} + or die "Feed format is missing\n"; } if ($format !~ /^(?:atom|rss)$/i) { - raise FeedInvalidFormat => $format; + die "Unknown format $format, use rss or atom\n"; } return $format; @@ -109,7 +102,7 @@ sub _create_rss_feed { _create_feed('RSS', $params); } -register_plugin for_versions => [1, 2]; +register_plugin for_versions => [2]; 1; @@ -117,8 +110,8 @@ register_plugin for_versions => [1, 2]; =head1 SYNOPSIS - use Dancer; - use Dancer::Plugin::Feed; + use Dancer2; + use Dancer2::Plugin::Feed; use Try::Tiny; get '/feed/:format' => sub { @@ -208,21 +201,11 @@ This method call B by setting the format to Atom. This method call B by setting the format to RSS. -=head1 Exception - -=over - -=item FeedNoFormat - -=item FeedInvalidFormat - -=back - =head1 CONTRIBUTING This module is developed on Github at: -L +L Feel free to fork the repo and submit pull requests @@ -238,10 +221,11 @@ Please report any bugs or feature requests in github. You can find documentation for this module with the perldoc command. - perldoc Dancer::Plugin::Feed + perldoc Dancer2::Plugin::Feed =head1 SEE ALSO -L +L L L +L diff --git a/t/00-load.t b/t/00-load.t deleted file mode 100644 index 29b19a0..0000000 --- a/t/00-load.t +++ /dev/null @@ -1,11 +0,0 @@ -use strict; -use warnings; - -use Test::More tests => 1; # last test to print - - -BEGIN { - use_ok( 'Dancer::Plugin::Feed' ) || print "Bail out"; -} - -diag( "Testing Dancer::Plugin::Feed $Dancer::Plugin::Feed::VERSION, Perl $], $^X" ); diff --git a/t/01-basic.t b/t/01-basic.t index f0eec88..598aa2d 100644 --- a/t/01-basic.t +++ b/t/01-basic.t @@ -3,13 +3,12 @@ use warnings; use Test::More import => ['!pass']; -use Dancer; -use Dancer::Test; - use lib 't/lib'; +use XML::Feed; use TestApp; -use XML::Feed; +use Dancer2; +use Dancer2::Test apps => [ 'TestApp' ]; plan tests => 32; @@ -21,7 +20,7 @@ is $res->{status}, 500, "response for GET /feed is 500"; for my $format (qw/atom rss/) { for my $route ("/feed/$format", "/other/feed/$format") { ok ($res = dancer_response(GET => $route)); - is ($res->{status}, 200); + is $res->status, 200, "$format - $route"; is ($res->header('Content-Type'), "application/$format+xml"); ok ( $feed = XML::Feed->parse( \$res->{content} ) ); is ( $feed->title, 'TestApp with ' . $format ); @@ -36,6 +35,9 @@ for my $format (qw/atom rss/) { $res = dancer_response GET => '/feed/foo'; is $res->{status}, 500, "response for GET /feed/foo is 500"; -setting plugins => { Feed => { format => 'atom' } }; +{ + package TestApp; + setting plugins => { Feed => { format => 'atom' } }; +} ok ($res = dancer_response(GET => '/feed')); is ($res->header('Content-Type'), 'application/atom+xml'); diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm index 866651c..e7411ee 100644 --- a/t/lib/TestApp.pm +++ b/t/lib/TestApp.pm @@ -1,7 +1,7 @@ -package t::lib::TestApp; +package TestApp; -use Dancer; -use Dancer::Plugin::Feed; +use Dancer2; +use Dancer2::Plugin::Feed; get '/feed' => sub { create_feed(