File Coverage

blib/lib/Dancer2/Plugin/Chain.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 30 30 100.0


line stmt bran cond sub pod time code
1             package Dancer2::Plugin::Chain;
2              
3             $Dancer2::Plugin::Chain::VERSION = '0.10';
4             $Dancer2::Plugin::Chain::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Dancer2::Plugin::Chain - Dancer2 add-on for route chaining.
9              
10             =head1 VERSION
11              
12             Version 0.10
13              
14             =cut
15              
16 4     4   733877 use 5.006;
  4         29  
17 4     4   19 use strict; use warnings;
  4     4   6  
  4         135  
  4         20  
  4         5  
  4         125  
18 4     4   1508 use Data::Dumper;
  4         17053  
  4         255  
19              
20 4     4   1805 use Dancer2::Plugin;
  4         570851  
  4         37  
21 4     4   122051 use Dancer2::Plugin::Chain::Router;
  4         13  
  4         472  
22              
23             =head1 DESCRIPTION
24              
25             A very simple plugin for L for chaining routes.I needed this for my other
26             project (in-progress) available on L.
27              
28             =head1 SYNOPSIS
29              
30             my $continent = chain '/continent/:continent' => sub { var 'site' => param('continent'); };
31             my $country = chain '/country/:country' => sub { var 'site' => param('country'); };
32             my $event = chain '/event/:event' => sub { var 'event' => param('event'); };
33             my $continent_event = chain $continent, $event;
34              
35             get chain $country, $event, '/schedule' => sub {
36             return sprintf("Schedule of %s in %s\n", var('event'), var('site'));
37             };
38              
39             get chain $continent_event, '/schedule' => sub {
40             return sprintf("Schedule of %s in %s\n", var('event'), var('site'));
41             };
42              
43             get chain $continent, sub { var 'temp' => var('site') },
44             $country, sub { var 'site' => join(', ', var('site'), var('temp')) },
45             $event, '/schedule' => sub {
46             return sprintf("Schedule of %s in %s\n", var('event'), var('site'));
47             };
48              
49             =head1 METHODS
50              
51             =head2 chain(@args)
52              
53             =cut
54              
55             register chain => sub {
56 7     7   165 my $dsl = shift;
57 7         16 my @args = @_;
58              
59 7         107 my $router = Dancer2::Plugin::Chain::Router->new({ args => \@args });
60 7 100       26 return wantarray ? $router->route : $router;
61             };
62              
63             register_plugin;
64              
65             =head1 AUTHOR
66              
67             Mohammad S Anwar, C<< >>
68              
69             =head1 REPOSITORY
70              
71             L
72              
73             =head1 ACKNOWLEDGEMENTS
74              
75             Inspired by the package L (Yanick Champoux ).
76              
77             =head1 SEE ALSO
78              
79             L
80              
81             =head1 BUGS
82              
83             Please report any bugs or feature requests to C,
84             or through the web interface at L.
85             I will be notified and then you'll automatically be notified of progress on your
86             bug as I make changes.
87              
88             =head1 SUPPORT
89              
90             You can find documentation for this module with the perldoc command.
91              
92             perldoc Dancer2::Plugin::Chain
93              
94             You can also look for information at:
95              
96             =over 4
97              
98             =item * RT: CPAN's request tracker (report bugs here)
99              
100             L
101              
102             =item * AnnoCPAN: Annotated CPAN documentation
103              
104             L
105              
106             =item * CPAN Ratings
107              
108             L
109              
110             =item * Search CPAN
111              
112             L
113              
114             =back
115              
116             =head1 LICENSE AND COPYRIGHT
117              
118             Copyright (C) 2015 - 2016 Mohammad S Anwar.
119              
120             This program is free software; you can redistribute it and / or modify it under
121             the terms of the the Artistic License (2.0). You may obtain a copy of the full
122             license at:
123              
124             L
125              
126             Any use, modification, and distribution of the Standard or Modified Versions is
127             governed by this Artistic License.By using, modifying or distributing the Package,
128             you accept this license. Do not use, modify, or distribute the Package, if you do
129             not accept this license.
130              
131             If your Modified Version has been derived from a Modified Version made by someone
132             other than you,you are nevertheless required to ensure that your Modified Version
133             complies with the requirements of this license.
134              
135             This license does not grant you the right to use any trademark, service mark,
136             tradename, or logo of the Copyright Holder.
137              
138             This license includes the non-exclusive, worldwide, free-of-charge patent license
139             to make, have made, use, offer to sell, sell, import and otherwise transfer the
140             Package with respect to any patent claims licensable by the Copyright Holder that
141             are necessarily infringed by the Package. If you institute patent litigation
142             (including a cross-claim or counterclaim) against any party alleging that the
143             Package constitutes direct or contributory patent infringement,then this Artistic
144             License to you shall terminate on the date that such litigation is filed.
145              
146             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
147             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
148             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
149             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
150             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
151             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
152             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
153              
154             =cut
155              
156             1; # End of Dancer2::Plugin::Chain