File Coverage

blib/lib/Dancer/Plugin/ProxyPath.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Dancer::Plugin::ProxyPath;
2              
3 2     2   50917 use warnings;
  2         5  
  2         59  
4 2     2   11 use strict;
  2         4  
  2         62  
5 2     2   2197 use Dancer ':syntax';
  2         828984  
  2         13  
6 2     2   2432 use Dancer::Plugin;
  2         4056  
  2         186  
7 2     2   2236 use Dancer::Plugin::ProxyPath::Proxy;
  2         5  
  2         358  
8              
9             =head1 NAME
10              
11             Dancer::Plugin::ProxyPath - Provides user-perspective paths
12              
13             =head1 VERSION
14              
15             Version 0.03
16              
17             =cut
18              
19             our $VERSION = '0.03';
20              
21             =head1 SYNOPSIS
22              
23             This module provides an alternative to using request->uri_for, which provides
24             server perspective paths. The paths produced by this module are made using
25             headers provided by Apache to determine what the path should be from the requester's
26             perspective. This is useful when you have deployed your Dancer app using the
27             ReverseProxy method: L
28              
29             Supposing a Dancer app hosted on http://private.server.com:5000 but
30             reachable at http://public.server.com/dancer-app, the following should apply:
31              
32             use Dancer::Plugin::ProxyPath;
33              
34             my $internal_path = request->uri_for("/path/to/elsewhere");
35             # http://private.server.com:5000/path/to/elsewhere
36              
37             my $external_path = proxy->uri_for("/path/to/elsewhere");
38             # http://public.server.com/dancer-app/path/to/elsewhere
39             ...
40              
41             # and in your templates: (assuming a passed variable $background)
42              
43            
44            
45              
46             If no proxy information is found, proxy->uri_for will
47             return the same paths as request->uri_for, making it work
48             in development as well.
49              
50             If the proxy is not mounted at the root level, you will
51             need to pass along the mounted location, using a header (See README).
52             You can set the name of the header you have chosen with the
53             plugin setting "base_header"
54              
55              
56             =head1 EXPORT
57              
58             One function is exported by default: proxy
59              
60             =head1 SUBROUTINES
61              
62             =head2 proxy
63              
64             Returns the proxy object, which has two methods: path and uri_for.
65              
66             See L
67              
68             =cut
69              
70             sub _get_base_header {
71 2     2   11 return plugin_setting->{"base_header"};
72             }
73              
74             register proxy => sub {
75 2     2   14 return Dancer::Plugin::ProxyPath::Proxy->instance(_get_base_header);
76             };
77              
78             before_template sub {
79             my $tokens = shift;
80             $tokens->{proxy} = Dancer::Plugin::ProxyPath::Proxy->instance;
81             };
82              
83             register_plugin;
84              
85             =head1 AUTHOR
86              
87             Alex Kalderimis, C<< >>
88              
89             =head1 BUGS
90              
91             Please report any bugs or feature requests to C, or through
92             the web interface at L. I will be notified, and then you'll
93             automatically be notified of progress on your bug as I make changes.
94              
95              
96             =head1 SUPPORT
97              
98             You can find documentation for this module with the perldoc command.
99              
100             perldoc Dancer::Plugin::ProxyPath
101              
102              
103             You can also look for information at:
104              
105             =over 4
106              
107             =item * RT: CPAN's request tracker
108              
109             L
110              
111             =item * AnnoCPAN: Annotated CPAN documentation
112              
113             L
114              
115             =item * CPAN Ratings
116              
117             L
118              
119             =item * Search CPAN
120              
121             L
122              
123             =back
124              
125              
126             =head1 ACKNOWLEDGEMENTS
127              
128             Dancer obviously, for being a great way to write a web-app.
129              
130             =head1 LICENSE AND COPYRIGHT
131              
132             Copyright 2011 Alex Kalderimis.
133              
134             This program is free software; you can redistribute it and/or modify it
135             under the terms of either: the GNU General Public License as published
136             by the Free Software Foundation; or the Artistic License.
137              
138             See http://dev.perl.org/licenses/ for more information.
139              
140              
141             =cut
142              
143             1; # End of Dancer::Plugin::ProxyPath