| 1 | package Plack::Middleware::Debug::CatalystSession; | ||
| 2 | |||
| 3 | use 5.008; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use parent qw(Plack::Middleware::Debug::Base); | ||
| 7 | |||
| 8 | use Catalyst; | ||
| 9 | |||
| 10 | use Class::Method::Modifiers qw(install_modifier); | ||
| 11 | use Data::Dumper; | ||
| 12 | use HTML::Entities qw/encode_entities_numeric/; | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | Plack::Middleware::Debug::CatalystSession - Debug panel to inspect the Catalyst Session | ||
| 17 | |||
| 18 | =head1 VERSION | ||
| 19 | |||
| 20 | Version 0.01003 | ||
| 21 | |||
| 22 | =cut | ||
| 23 | |||
| 24 | our $VERSION = '0.01004'; | ||
| 25 | # Starting with Catalyst 5.90097, the environment given to psgi middleware | ||
| 26 | # components was localized. This effectively made $c->req->env read only. | ||
| 27 | # If we are on those versions of Catalyst, we want to store a reference | ||
| 28 | # to the environment in a local variable. | ||
| 29 | use constant LOCALIZED_PSGI_ENV => $Catalyst::VERSION >= 5.90097 && $Catalyst::VERSION < 5.90100; | ||
| 30 | my $psgi_env; # Unused if LOCALIZED_PSGI_ENV is true | ||
| 31 | my $env_key = 'plack.middleware.catalyst_session'; | ||
| 32 | |||
| 33 | install_modifier 'Catalyst', 'before', 'finalize' => sub { | ||
| 34 | my $c = shift; | ||
| 35 | |||
| 36 | local $Data::Dumper::Terse = 1; | ||
| 37 | local $Data::Dumper::Indent = 1; | ||
| 38 | local $Data::Dumper::Deparse = 1; | ||
| 39 | my $session = | ||
| 40 | encode_entities_numeric( Dumper( $c->session ) ); | ||
| 41 | if (LOCALIZED_PSGI_ENV) { | ||
| 42 | $psgi_env->{$env_key} = $session; | ||
| 43 | } else { | ||
| 44 | $c->req->env->{$env_key} = $session; | ||
| 45 | } | ||
| 46 | }; | ||
| 47 | |||
| 48 | sub run { | ||
| 49 | my($self, $env, $panel) = @_; | ||
| 50 | if (LOCALIZED_PSGI_ENV) { | ||
| 51 | # At this point, $env is NOT a localized reference, so we store it | ||
| 52 | $psgi_env = $env; | ||
| 53 | } | ||
| 54 | |||
| 55 | return sub { | ||
| 56 | my $res = shift; | ||
| 57 | |||
| 58 | my $session = delete $env->{$env_key} || 'No Session'; | ||
| 59 | $panel->content("<pre>$session</pre>"); | ||
| 60 | if (LOCALIZED_PSGI_ENV) { | ||
| 61 | # Clean up our stored reference | ||
| 62 | $psgi_env = undef; | ||
| 63 | } | ||
| 64 | }; | ||
| 65 | } | ||
| 66 | |||
| 67 | =head1 SYNOPSIS | ||
| 68 | |||
| 69 | builder { | ||
| 70 | enable "Debug"; | ||
| 71 | enable "Debug::CatalystSession"; | ||
| 72 | sub { MyApp->run(@_) }; | ||
| 73 | }; | ||
| 74 | |||
| 75 | or | ||
| 76 | |||
| 77 | __PACKAGE__->config( | ||
| 78 | 'psgi_middleware', [ | ||
| 79 | 'Debug' => {panels => [ | ||
| 80 | 'CatalystSession' | ||
| 81 | ]}, | ||
| 82 | ] | ||
| 83 | ); | ||
| 84 | |||
| 85 | =head1 AUTHOR | ||
| 86 | |||
| 87 | Thomas Kuyper, C<< <tkuyper at cpan.org> >> | ||
| 88 | |||
| 89 | =head1 BUGS | ||
| 90 | |||
| 91 | Please report any bugs or feature requests to C<bug-plack-middleware-debug-catalystsession at rt.cpan.org>, or through | ||
| 92 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Plack-Middleware-Debug-CatalystSession>. I will be notified, and then you'll | ||
| 93 | automatically be notified of progress on your bug as I make changes. | ||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | =head1 SUPPORT | ||
| 99 | |||
| 100 | You can find documentation for this module with the perldoc command. | ||
| 101 | |||
| 102 | perldoc Plack::Middleware::Debug::CatalystSession | ||
| 103 | |||
| 104 | |||
| 105 | You can also look for information at: | ||
| 106 | |||
| 107 | =over 4 | ||
| 108 | |||
| 109 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 110 | |||
| 111 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Plack-Middleware-Debug-CatalystSession> | ||
| 112 | |||
| 113 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 114 | |||
| 115 | L<http://annocpan.org/dist/Plack-Middleware-Debug-CatalystSession> | ||
| 116 | |||
| 117 | =item * CPAN Ratings | ||
| 118 | |||
| 119 | L<http://cpanratings.perl.org/d/Plack-Middleware-Debug-CatalystSession> | ||
| 120 | |||
| 121 | =item * Search CPAN | ||
| 122 | |||
| 123 | L<http://search.cpan.org/dist/Plack-Middleware-Debug-CatalystSession/> | ||
| 124 | |||
| 125 | =back | ||
| 126 | |||
| 127 | |||
| 128 | =head1 ACKNOWLEDGEMENTS | ||
| 129 | |||
| 130 | For L<Plack::Middleware::Debug::CatalystStash> from which this is derived: | ||
| 131 | |||
| 132 | Mark Ellis E<lt>markellis@cpan.orgE<gt> | ||
| 133 | |||
| 134 | =head1 SEE ALSO | ||
| 135 | |||
| 136 | L<Plack::Middleware::Debug::CatalystStash> | ||
| 137 | |||
| 138 | L<Plack::Middleware::Debug> | ||
| 139 | |||
| 140 | =head1 LICENSE AND COPYRIGHT | ||
| 141 | |||
| 142 | Copyright 2014 Thomas Kuyper. | ||
| 143 | |||
| 144 | This program is free software; you can redistribute it and/or modify it | ||
| 145 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 146 | copy of the full license at: | ||
| 147 | |||
| 148 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 149 | |||
| 150 | Any use, modification, and distribution of the Standard or Modified | ||
| 151 | Versions is governed by this Artistic License. By using, modifying or | ||
| 152 | distributing the Package, you accept this license. Do not use, modify, | ||
| 153 | or distribute the Package, if you do not accept this license. | ||
| 154 | |||
| 155 | If your Modified Version has been derived from a Modified Version made | ||
| 156 | by someone other than you, you are nevertheless required to ensure that | ||
| 157 | your Modified Version complies with the requirements of this license. | ||
| 158 | |||
| 159 | This license does not grant you the right to use any trademark, service | ||
| 160 | mark, tradename, or logo of the Copyright Holder. | ||
| 161 | |||
| 162 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 163 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 164 | otherwise transfer the Package with respect to any patent claims | ||
| 165 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 166 | Package. If you institute patent litigation (including a cross-claim or | ||
| 167 | counterclaim) against any party alleging that the Package constitutes | ||
| 168 | direct or contributory patent infringement, then this Artistic License | ||
| 169 | to you shall terminate on the date that such litigation is filed. | ||
| 170 | |||
| 171 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 172 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 173 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 174 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 175 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 176 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 177 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 178 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 179 | |||
| 180 | |||
| 181 | =cut | ||
| 182 | |||
| 183 | 1; # End of Plack::Middleware::Debug::CatalystSession |