| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Catalyst::Plugin::Session::Defaults; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
36415
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
38
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3122
|
use Storable (); |
|
|
1
|
|
|
|
|
5093
|
|
|
|
1
|
|
|
|
|
25
|
|
|
9
|
1
|
|
|
1
|
|
9
|
use Carp (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
64
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub default_session_data { |
|
14
|
4
|
|
|
4
|
1
|
691
|
my $c = shift; |
|
15
|
4
|
|
50
|
|
|
24
|
my $def = $c->config->{session}{defaults} || {}; |
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
no warnings "uninitialized"; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
212
|
|
|
18
|
4
|
50
|
|
|
|
35
|
Carp::croak("The default session data must be a hash reference") |
|
19
|
|
|
|
|
|
|
unless ref $def eq "HASH"; |
|
20
|
|
|
|
|
|
|
|
|
21
|
4
|
|
|
|
|
223
|
return Storable::dclone( $def ); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub initialize_session_data { |
|
25
|
3
|
|
|
3
|
1
|
6
|
my ( $c, @args ) = @_; |
|
26
|
3
|
|
|
|
|
21
|
my $data = $c->NEXT::initialize_session_data( @args ); |
|
27
|
|
|
|
|
|
|
|
|
28
|
3
|
|
|
|
|
270
|
my $defaults = $c->default_session_data; |
|
29
|
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
8
|
@{ $data }{ keys %$defaults } = values %$defaults; |
|
|
3
|
|
|
|
|
8
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
17
|
return $data; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__PACKAGE__; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=pod |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Catalyst::Plugin::Session::Defaults - Default values in your session. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use Catalyst qw/ |
|
48
|
|
|
|
|
|
|
Session |
|
49
|
|
|
|
|
|
|
Session::Store::Moose |
|
50
|
|
|
|
|
|
|
Session::State::Cookie |
|
51
|
|
|
|
|
|
|
Session::Defaults |
|
52
|
|
|
|
|
|
|
/; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__PACKAGE__->config->{session}{defaults} = { |
|
55
|
|
|
|
|
|
|
likes_moose => 1, |
|
56
|
|
|
|
|
|
|
}; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This plugin lets you add default values to the intiial data that a session will |
|
61
|
|
|
|
|
|
|
be created with. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
You can either go with a hash in the session configuration key C<defaults>, or |
|
64
|
|
|
|
|
|
|
you can override the C<default_session_data> method to return a hash dynamically. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 METHODS |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=over 4 |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item default_session_data |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This method returns a deep clone of |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
YourApp->config->{session}{defaults} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
or an empty hash if there is no such key. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
It will die on bad data. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=back |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 OVERRIDDEN METHODS |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 4 |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item initialize_session_data |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This method is overridden to provide the hook that calls |
|
89
|
|
|
|
|
|
|
C<default_session_data>. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::Plugin::Session> |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHOR |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Yuval Kogman, C<nothingmuch@woobling.org> |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 LICENSE |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
|
104
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
|
107
|
|
|
|
|
|
|
|