| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dancer2::Plugin::PageHistory; |
|
2
|
3
|
|
|
3
|
|
523070
|
use utf8; |
|
|
3
|
|
|
|
|
12
|
|
|
|
3
|
|
|
|
|
14
|
|
|
3
|
3
|
|
|
3
|
|
67
|
use strict; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
43
|
|
|
4
|
3
|
|
|
3
|
|
22
|
use warnings; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
121
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=encoding utf8 |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Dancer2::Plugin::PageHistory - store recent page history for user into session |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.208 |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.208'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
388
|
use Dancer2::Core::Types qw/Bool HashRef Str/; |
|
|
3
|
|
|
|
|
7465
|
|
|
|
3
|
|
|
|
|
174
|
|
|
21
|
3
|
|
|
3
|
|
1336
|
use Dancer2::Plugin; |
|
|
3
|
|
|
|
|
62889
|
|
|
|
3
|
|
|
|
|
17
|
|
|
22
|
3
|
|
|
3
|
|
16658
|
use Dancer2::Plugin::PageHistory::PageSet; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
74
|
|
|
23
|
3
|
|
|
3
|
|
1146
|
use Dancer2::Plugin::PageHistory::Page; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
85
|
|
|
24
|
3
|
|
|
3
|
|
1225
|
use Data::Structure::Util qw/unbless/; |
|
|
3
|
|
|
|
|
7065
|
|
|
|
3
|
|
|
|
|
1138
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $history_name = 'page_history'; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
get '/product/:sku/:name' => sub { |
|
31
|
|
|
|
|
|
|
add_to_history( |
|
32
|
|
|
|
|
|
|
type => 'product', |
|
33
|
|
|
|
|
|
|
title => param('name'), |
|
34
|
|
|
|
|
|
|
attributes => { sku => param('sku') } |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
}; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
hook 'before_template_render' => sub { |
|
39
|
|
|
|
|
|
|
my $tokens = shift; |
|
40
|
|
|
|
|
|
|
$tokens->{previous_page} = history->previous_page->uri; |
|
41
|
|
|
|
|
|
|
}; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
The C keyword which is exported by this plugin allows you to |
|
46
|
|
|
|
|
|
|
add interesting items to the history lists which are returned using the |
|
47
|
|
|
|
|
|
|
C keyword. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 KEYWORDS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 add_to_history |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Adds a page via L. Both of |
|
54
|
|
|
|
|
|
|
L and |
|
55
|
|
|
|
|
|
|
L are optional |
|
56
|
|
|
|
|
|
|
arguments |
|
57
|
|
|
|
|
|
|
which will be set automatically from the current request if they are not |
|
58
|
|
|
|
|
|
|
supplied. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 history |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Returns the current L object from the |
|
63
|
|
|
|
|
|
|
user's session. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SUPPORTED SESSION ENGINES |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
L, |
|
68
|
|
|
|
|
|
|
L, |
|
69
|
|
|
|
|
|
|
L, |
|
70
|
|
|
|
|
|
|
L, |
|
71
|
|
|
|
|
|
|
L, |
|
72
|
|
|
|
|
|
|
L, |
|
73
|
|
|
|
|
|
|
L, |
|
74
|
|
|
|
|
|
|
L, |
|
75
|
|
|
|
|
|
|
L, |
|
76
|
|
|
|
|
|
|
L, |
|
77
|
|
|
|
|
|
|
L |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
No configuration is necessarily required. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
If you wish to have arguments passed to |
|
84
|
|
|
|
|
|
|
L these can be added to your |
|
85
|
|
|
|
|
|
|
configuration along with configuration for the plugin itself, e.g.: |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
plugins: |
|
88
|
|
|
|
|
|
|
PageHistory: |
|
89
|
|
|
|
|
|
|
add_all_pages: 1 |
|
90
|
|
|
|
|
|
|
ingore_ajax: 1 |
|
91
|
|
|
|
|
|
|
history_name: someothername |
|
92
|
|
|
|
|
|
|
PageSet: |
|
93
|
|
|
|
|
|
|
default_type: all |
|
94
|
|
|
|
|
|
|
fallback_page: |
|
95
|
|
|
|
|
|
|
path: "/" |
|
96
|
|
|
|
|
|
|
max_items: 20 |
|
97
|
|
|
|
|
|
|
methods: |
|
98
|
|
|
|
|
|
|
- default |
|
99
|
|
|
|
|
|
|
- product |
|
100
|
|
|
|
|
|
|
- navigation |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Configuration options for the plugin itself: |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * add_all_pages |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Defaults to 0. Set to 1 to have all pages added to the list |
|
109
|
|
|
|
|
|
|
L in the L hook. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * ignore_ajax |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
If L is true this controls whether ajax requests are added to |
|
114
|
|
|
|
|
|
|
the list L in the |
|
115
|
|
|
|
|
|
|
L hook. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Defaults to 0. Set to 1 to have ajax requests ignored. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item * history_name |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This setting can be used to change the name of the key used to store |
|
122
|
|
|
|
|
|
|
the history object in the session from the default C to |
|
123
|
|
|
|
|
|
|
something else. This is also the key used for name of the token |
|
124
|
|
|
|
|
|
|
containing the history object that is passed to templates. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 HOOKS |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This plugin makes use of the following hooks: |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 before |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Add current page to history. See L and L. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 before_template_render |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Puts history into the token C. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
has add_all_pages => ( |
|
143
|
|
|
|
|
|
|
is => 'ro', |
|
144
|
|
|
|
|
|
|
isa => Bool, |
|
145
|
|
|
|
|
|
|
from_config => sub { 0 }, |
|
146
|
|
|
|
|
|
|
); |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
has ignore_ajax => ( |
|
149
|
|
|
|
|
|
|
is => 'ro', |
|
150
|
|
|
|
|
|
|
isa => Bool, |
|
151
|
|
|
|
|
|
|
from_config => sub { 0 }, |
|
152
|
|
|
|
|
|
|
); |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
has history_name => ( |
|
155
|
|
|
|
|
|
|
is => 'ro', |
|
156
|
|
|
|
|
|
|
isa => Str, |
|
157
|
|
|
|
|
|
|
from_config => sub { 'page_history' }, |
|
158
|
|
|
|
|
|
|
); |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
has page_set_args => ( |
|
161
|
|
|
|
|
|
|
is => 'ro', |
|
162
|
|
|
|
|
|
|
isa => HashRef, |
|
163
|
|
|
|
|
|
|
from_config => 'PageSet', |
|
164
|
|
|
|
|
|
|
default => sub { +{} }, |
|
165
|
|
|
|
|
|
|
); |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
plugin_keywords 'add_to_history', 'history'; |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub BUILD { |
|
170
|
2
|
|
|
2
|
0
|
3803
|
my $plugin = shift; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
$plugin->app->add_hook( |
|
173
|
|
|
|
|
|
|
Dancer2::Core::Hook->new( |
|
174
|
|
|
|
|
|
|
name => 'before', |
|
175
|
|
|
|
|
|
|
code => sub { |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
return |
|
178
|
16
|
100
|
66
|
16
|
|
151404
|
if ( !$plugin->add_all_pages |
|
|
|
|
33
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|| ( $plugin->ignore_ajax |
|
180
|
|
|
|
|
|
|
&& $plugin->app->request->is_ajax ) ); |
|
181
|
|
|
|
|
|
|
|
|
182
|
12
|
|
|
|
|
1634
|
$plugin->add_to_history; |
|
183
|
|
|
|
|
|
|
}, |
|
184
|
|
|
|
|
|
|
) |
|
185
|
2
|
|
|
|
|
50
|
); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
$plugin->app->add_hook( |
|
188
|
|
|
|
|
|
|
Dancer2::Core::Hook->new( |
|
189
|
|
|
|
|
|
|
name => 'before_template_render', |
|
190
|
|
|
|
|
|
|
code => sub { |
|
191
|
0
|
|
|
0
|
|
0
|
my $tokens = shift; |
|
192
|
0
|
|
|
|
|
0
|
$tokens->{$plugin->history_name} = $plugin->history; |
|
193
|
|
|
|
|
|
|
}, |
|
194
|
|
|
|
|
|
|
) |
|
195
|
2
|
|
|
|
|
764
|
); |
|
196
|
|
|
|
|
|
|
}; |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub add_to_history { |
|
199
|
14
|
|
|
14
|
1
|
349
|
my ( $plugin, @args ) = @_; |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my %args = ( |
|
202
|
|
|
|
|
|
|
path => $plugin->app->request->path, |
|
203
|
|
|
|
|
|
|
query_string => $plugin->app->request->env->{QUERY_STRING}, |
|
204
|
14
|
|
|
|
|
56
|
@args, |
|
205
|
|
|
|
|
|
|
); |
|
206
|
|
|
|
|
|
|
|
|
207
|
14
|
|
|
|
|
134
|
$plugin->app->log( "debug", "adding page to history: ", \%args ); |
|
208
|
|
|
|
|
|
|
|
|
209
|
14
|
|
|
|
|
10416
|
my $history = $plugin->history; |
|
210
|
|
|
|
|
|
|
|
|
211
|
14
|
|
|
|
|
1100
|
$history->add( %args ); |
|
212
|
|
|
|
|
|
|
|
|
213
|
14
|
|
|
|
|
290
|
$plugin->app->session->write( |
|
214
|
|
|
|
|
|
|
$plugin->history_name => unbless( $history->pages ) ); |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub history { |
|
218
|
14
|
|
|
14
|
1
|
21
|
my $plugin = shift; |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
return Dancer2::Plugin::PageHistory::PageSet->new( |
|
221
|
14
|
|
100
|
|
|
17
|
%{ $plugin->page_set_args }, |
|
|
14
|
|
|
|
|
163
|
|
|
222
|
|
|
|
|
|
|
pages => $plugin->app->session->read( $plugin->history_name ) || {}, |
|
223
|
|
|
|
|
|
|
); |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 TODO |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=over |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * Add more tests |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=back |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 AUTHOR |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Peter Mottram (SysPete), C<< >> |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Slaven Rezić (eserte) - GH issues #1, #2, #3 |
|
241
|
|
|
|
|
|
|
Andreas J. König (andk) - GH issue #4 |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 BUGS |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Please report any bugs or feature requests via the project's GitHub |
|
246
|
|
|
|
|
|
|
issue tracker: |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
L |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of |
|
251
|
|
|
|
|
|
|
progress on your bug as I make changes. PRs are always welcome. |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head1 SUPPORT |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
perldoc Dancer2::Plugin::PageHistory |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
You can also look for information at: |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=over 4 |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item * L |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item * L |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=back |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Copyright 2015-2016 Peter Mottram (SysPete). |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
274
|
|
|
|
|
|
|
it under the same terms as the Perl 5 programming language system itself. |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=cut |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
1; # End of Dancer2::Plugin::PageHistory |