line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Plugin::PageHistory; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Dancer::Plugin::PageHistory - store recent page history for user into session |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Version 0.100 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.100'; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
218546
|
use Dancer ':syntax'; |
|
2
|
|
|
|
|
199534
|
|
|
2
|
|
|
|
|
11
|
|
16
|
2
|
|
|
2
|
|
1379
|
use Dancer::Plugin; |
|
2
|
|
|
|
|
2253
|
|
|
2
|
|
|
|
|
121
|
|
17
|
2
|
|
|
2
|
|
386
|
use Dancer::Plugin::PageHistory::PageSet; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
18
|
2
|
|
|
2
|
|
663
|
use Dancer::Plugin::PageHistory::Page; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
19
|
2
|
|
|
2
|
|
1042
|
use Data::Structure::Util qw/unbless/; |
|
2
|
|
|
|
|
5151
|
|
|
2
|
|
|
|
|
755
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $history_name = 'page_history'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
get '/product/:sku/:name' => sub { |
26
|
|
|
|
|
|
|
add_to_history( |
27
|
|
|
|
|
|
|
type => 'product', |
28
|
|
|
|
|
|
|
title => param('name'), |
29
|
|
|
|
|
|
|
attributes => { sku => param('sku') } |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
hook 'before_template_render' => sub { |
34
|
|
|
|
|
|
|
my $tokens = shift; |
35
|
|
|
|
|
|
|
$tokens->{previous_page} = history->previous_page->uri; |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DESCRIPTION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
The C keyword which is exported by this plugin allows you to |
41
|
|
|
|
|
|
|
add interesting items to the history lists which are returned using the |
42
|
|
|
|
|
|
|
C keyword. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 KEYWORDS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 add_to_history |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Adds a page via L. Both of |
49
|
|
|
|
|
|
|
L and |
50
|
|
|
|
|
|
|
L are optional arguments |
51
|
|
|
|
|
|
|
which will be set automatically from the current request if they are not |
52
|
|
|
|
|
|
|
supplied. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 history |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Returns the current L object from the |
57
|
|
|
|
|
|
|
user's session. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SUPPORTED SESSION ENGINES |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
L, |
62
|
|
|
|
|
|
|
L, |
63
|
|
|
|
|
|
|
L, |
64
|
|
|
|
|
|
|
L, |
65
|
|
|
|
|
|
|
L, |
66
|
|
|
|
|
|
|
L, |
67
|
|
|
|
|
|
|
L, |
68
|
|
|
|
|
|
|
L, |
69
|
|
|
|
|
|
|
L, |
70
|
|
|
|
|
|
|
L, |
71
|
|
|
|
|
|
|
L |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 CAVEATS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
L and L either don't handle |
76
|
|
|
|
|
|
|
destroy at all or else do it wrong so I suggest you avoid those modules if |
77
|
|
|
|
|
|
|
you want things like logout to work. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
See . |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 CONFIGURATION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
No configuration is necessarily required. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
If you wish to have arguments passed to |
86
|
|
|
|
|
|
|
L these can be added to your |
87
|
|
|
|
|
|
|
configuration along with configuration for the plugin itself, e.g.: |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
plugins: |
90
|
|
|
|
|
|
|
PageHistory: |
91
|
|
|
|
|
|
|
add_all_pages: 1 |
92
|
|
|
|
|
|
|
ingore_ajax: 1 |
93
|
|
|
|
|
|
|
history_name: someothername |
94
|
|
|
|
|
|
|
PageSet: |
95
|
|
|
|
|
|
|
default_type: all |
96
|
|
|
|
|
|
|
fallback_page: |
97
|
|
|
|
|
|
|
path: "/" |
98
|
|
|
|
|
|
|
max_items: 20 |
99
|
|
|
|
|
|
|
methods: |
100
|
|
|
|
|
|
|
- default |
101
|
|
|
|
|
|
|
- product |
102
|
|
|
|
|
|
|
- navigation |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Configuration options for the plugin itself: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * add_all_pages |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Defaults to 0. Set to 1 to have all pages added to the list |
111
|
|
|
|
|
|
|
L in the L hook. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * ignore_ajax |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
If L is true this controls whether ajax requests are added to |
116
|
|
|
|
|
|
|
the list L in the |
117
|
|
|
|
|
|
|
L hook. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Defaults to 0. Set to 1 to have ajax requests ignored. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * history_name |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This setting can be used to change the name of the key used to store |
124
|
|
|
|
|
|
|
the history object in the session from the default C to |
125
|
|
|
|
|
|
|
something else. This is also the key used for name of the token |
126
|
|
|
|
|
|
|
containing the history object that is passed to templates and also the var |
127
|
|
|
|
|
|
|
used to cache the history object during the request lifetime. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 HOOKS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This plugin makes use of the following hooks: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 before |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Add current page to history. See L and L. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
hook before => sub { |
142
|
|
|
|
|
|
|
my $conf = plugin_setting; |
143
|
|
|
|
|
|
|
return |
144
|
|
|
|
|
|
|
if ( !$conf->{add_all_pages} |
145
|
|
|
|
|
|
|
|| ( $conf->{ignore_ajax} && request->is_ajax ) ); |
146
|
|
|
|
|
|
|
add_to_history(); |
147
|
|
|
|
|
|
|
}; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 before_template_render |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Puts history into the token C. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
hook before_template_render => sub { |
156
|
|
|
|
|
|
|
my $tokens = shift; |
157
|
|
|
|
|
|
|
my $name = plugin_setting->{history_name} || $history_name; |
158
|
|
|
|
|
|
|
$tokens->{$name} = history(); |
159
|
|
|
|
|
|
|
}; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub add_to_history { |
162
|
12
|
|
33
|
12
|
|
4172
|
my $name = plugin_setting->{history_name} || $history_name; |
163
|
12
|
|
|
|
|
310
|
my ( $self, @args ) = plugin_args(@_); |
164
|
|
|
|
|
|
|
|
165
|
12
|
|
|
|
|
50
|
my $path = request->path; |
166
|
12
|
|
|
|
|
121
|
my $query = params('query'); |
167
|
|
|
|
|
|
|
|
168
|
12
|
|
|
|
|
1740
|
my %args = ( |
169
|
|
|
|
|
|
|
path => $path, |
170
|
|
|
|
|
|
|
query => $query, |
171
|
|
|
|
|
|
|
@args, |
172
|
|
|
|
|
|
|
); |
173
|
|
|
|
|
|
|
|
174
|
12
|
|
|
|
|
42
|
debug "adding page to history: ", \%args; |
175
|
|
|
|
|
|
|
|
176
|
12
|
|
|
|
|
81
|
my $history = history(); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# add the page and save back to session with pages all unblessed |
179
|
12
|
|
|
|
|
47
|
$history->add( %args ); |
180
|
12
|
|
|
|
|
255
|
session $name => unbless( $history->pages ); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub history { |
184
|
12
|
|
|
12
|
|
31
|
my $conf = plugin_setting; |
185
|
12
|
|
33
|
|
|
292
|
my $name = $conf->{history_name} || $history_name; |
186
|
12
|
|
|
|
|
23
|
my $history; |
187
|
|
|
|
|
|
|
|
188
|
12
|
100
|
|
|
|
34
|
if ( defined var($name) ) { |
189
|
2
|
|
|
|
|
17
|
$history = var($name); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
else { |
192
|
|
|
|
|
|
|
|
193
|
10
|
|
|
|
|
109
|
my $session_history = session($name); |
194
|
10
|
100
|
|
|
|
23358
|
$session_history = {} unless ref($session_history) eq 'HASH'; |
195
|
|
|
|
|
|
|
|
196
|
10
|
50
|
|
|
|
37
|
my %args = $conf->{PageSet} ? %{ $conf->{PageSet} } : (); |
|
10
|
|
|
|
|
37
|
|
197
|
10
|
|
|
|
|
20
|
$args{pages} = $session_history; |
198
|
|
|
|
|
|
|
|
199
|
10
|
|
|
|
|
326
|
$history = Dancer::Plugin::PageHistory::PageSet->new(%args); |
200
|
10
|
|
|
|
|
283
|
var $name => $history; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
12
|
|
|
|
|
110
|
return $history; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
register add_to_history => \&add_to_history; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
register history => \&history; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
register_plugin; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 TODO |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=over |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item * Add more tests |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * Add support for more session engines |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item * Create Dancer2 plugin |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item * investigate C problems with L |
223
|
|
|
|
|
|
|
and L |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=back |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 AUTHOR |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Peter Mottram (SysPete), "peter@sysnix.com" |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 BUGS |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This is BETA software so bugs and missing features are expected. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Please report any bugs or feature requests via the project's GitHub |
236
|
|
|
|
|
|
|
issue tracker: |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
L |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of |
241
|
|
|
|
|
|
|
progress on your bug as I make changes. PRs are always welcome. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 SUPPORT |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
perldoc Dancer::Plugin::PageHistory |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
You can also look for information at: |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=over 4 |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=item * L |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item * L |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=back |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Copyright 2015 Peter Mottram (SysPete). |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
264
|
|
|
|
|
|
|
it under the same terms as the Perl 5 programming language system itself. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
1; # End of Dancer::Plugin::PageHistory |