File Coverage

blib/lib/Dancer/Plugin/Scoped.pm
Criterion Covered Total %
statement 12 20 60.0
branch n/a
condition n/a
subroutine 4 6 66.6
pod 1 1 100.0
total 17 27 62.9


line stmt bran cond sub pod time code
1             package Dancer::Plugin::Scoped;
2 1     1   28004 use base 'Exporter';
  1         2  
  1         98  
3             @EXPORT = qw( scoped );
4 1     1   6 use warnings;
  1         1  
  1         31  
5 1     1   6 use strict;
  1         6  
  1         109  
6              
7             our $VERSION = '0.02';
8              
9             sub scoped (&) {
10 0     0 1   my ($code) = @_;
11 0           my $caller = caller;
12             return sub {
13 1     1   5 no strict 'refs';
  1         2  
  1         164  
14 0     0     while (my ($k, $v) = each %{Dancer::SharedData->request->params}) {
  0            
15 0           ${"$caller\::$k"} = $v;
  0            
16             }
17 0           $code->(@_);
18 0           };
19             }
20              
21             =head1 NAME
22              
23             Dancer::Plugin::Scoped - Allows to set params variables in scope of route handler
24              
25             =head1 VERSION
26              
27             Version 0.02
28              
29             =cut
30              
31             =head1 SYNOPSIS
32              
33             use Dancer;
34             use Dancer::Plugin::Scoped;
35              
36             any '/' => scoped {
37             our ($page, $test);
38             template $page, { test => $test };
39             };
40              
41             $page, $test - these variables will be set according to params data, e.g. $page is a syntactic
42             alias to params->{page}.
43              
44             =head1 EXPORT
45              
46             scoped
47              
48             =head1 SUBROUTINES/METHODS
49              
50             =head2 scoped
51              
52             A replacement for sub in route handler definition. It sets variables passed in params hash which
53             is accessible via our declarations.
54              
55             =cut
56              
57             =head1 AUTHOR
58              
59             Roman Galeev, C<< >>
60              
61             =head1 BUGS
62              
63             Please report any bugs or feature requests to C, or through
64             the web interface at L. I will be notified, and then you'll
65             automatically be notified of progress on your bug as I make changes.
66              
67             =head1 SUPPORT
68              
69             You can find documentation for this module with the perldoc command.
70              
71             perldoc Dancer::Plugin::Scoped
72              
73             You can also look for information at:
74              
75             =over 4
76              
77             =item * RT: CPAN's request tracker
78              
79             L
80              
81             =item * AnnoCPAN: Annotated CPAN documentation
82              
83             L
84              
85             =item * CPAN Ratings
86              
87             L
88              
89             =item * Search CPAN
90              
91             L
92              
93             =back
94              
95             =head1 ACKNOWLEDGEMENTS
96              
97             =head1 LICENSE AND COPYRIGHT
98              
99             Copyright 2010 Roman Galeev.
100              
101             This program is free software; you can redistribute it and/or modify it
102             under the terms of either: the GNU General Public License as published
103             by the Free Software Foundation; or the Artistic License.
104              
105             See http://dev.perl.org/licenses/ for more information.
106              
107             =cut
108              
109             1; # End of Dancer::Plugin::Scoped