File Coverage

blib/lib/Plack/Middleware/Return/MultiLevel/Utils.pm
Criterion Covered Total %
statement 19 19 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 29 30 96.6


line stmt bran cond sub pod time code
1 1     1   697 use strict;
  1         1  
  1         37  
2 1     1   5 use warnings;
  1         34  
  1         40  
3              
4             package Plack::Middleware::Return::MultiLevel::Utils;
5              
6 1     1   6 use Scalar::Util;
  1         2  
  1         41  
7 1     1   4 use Exporter 'import';
  1         2  
  1         35  
8 1     1   6 use Plack::Middleware::Return::MultiLevel;
  1         2  
  1         173  
9              
10             our @EXPORT_OK = qw(return_to_level return_to_default_level);
11              
12             sub return_to_level {
13 3     3 1 110 my ($proto, $level_name, @returning) = @_;
14 3 50       15 my $env = Scalar::Util::blessed($proto) ? $proto->env : $proto;
15 3         11 return Plack::Middleware::Return::MultiLevel::_return_level(
16             $env, $level_name, @returning);
17             }
18              
19             sub return_to_default_level {
20 1     1 1 78 return return_to_level(shift, Plack::Middleware::Return::MultiLevel::DEFAULT_LEVEL_NAME, @_);
21             }
22              
23              
24             =head1 TITLE
25            
26             Plack::Middleware::Return::MultiLevel::Utils - Ease of Use Utility subroutines
27              
28             =head1 SYNOPSIS
29              
30             use Plack::Middleware::Return::MultiLevel::Utils
31             qw/return_to_level return_to_default_level/;
32              
33             return_to_default_level($env,
34             [200, ['Content-Type', 'text/plain'], ['default']]);
35              
36             return_to_level($env, 'set_level_name',
37             [200, ['Content-Type', 'text/plain'], ['named level']]);
38              
39             =head1 DESCRIPTION
40              
41             Ideally you'd invoke your L return points via one if these
42             importable subroutines, rather than reaching into the C hash. This
43             gives you better encapsulation and allows the underlying code to change without
44             busted your use.
45              
46             =head1 EXPORTS
47              
48             This class defines the following exportable subroutines
49              
50             =head2 return_to_default_level
51              
52             return_to_default_level($env,
53             [200, ['Content-Type', 'text/plain'], ['default']]);
54              
55             Requires C<$psgi_env> and a response, which typically is a PSGI type response,
56             athough you can return anything you want if there is middleware to convert it to
57             an acceptable PSGI style response, for example.
58              
59             This can also be imported and called as a method on an object that does the C
60             method. For example:
61              
62             $catalyst_context->request->return_to_default_level(\@response);
63              
64             =head2 return_to_level
65              
66             return_to_level($env, 'set_level_name',
67             [200, ['Content-Type', 'text/plain'], ['named level']]);
68              
69             Just like L except that the second argument is the name of a
70             return level that you set. Also can be called as a method against an object that
71             does C.
72            
73             =head1 AUTHOR
74            
75             See L
76              
77             =head1 SEE ALSO
78              
79             L
80            
81             =head1 COPYRIGHT & LICENSE
82            
83             See L
84              
85             =cut
86              
87             1;