line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pinwheel::Context; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
128100
|
use strict; |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
528
|
|
4
|
13
|
|
|
13
|
|
87
|
use warnings; |
|
13
|
|
|
|
|
40
|
|
|
13
|
|
|
|
|
8295
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our %context; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub get |
11
|
|
|
|
|
|
|
{ |
12
|
767
|
100
|
|
767
|
1
|
21668
|
my $key = @_ ? shift : '*' . caller(); |
13
|
767
|
|
100
|
|
|
7085
|
$context{$key} ||= {}; |
14
|
767
|
|
|
|
|
3512
|
return $context{$key}; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub set |
18
|
|
|
|
|
|
|
{ |
19
|
23
|
100
|
|
23
|
1
|
166
|
my $key = (@_ & 1) ? shift : '*' . caller(); |
20
|
23
|
|
|
|
|
75
|
my %values = @_; |
21
|
23
|
|
|
|
|
97
|
$context{$key} = \%values; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub reset |
25
|
|
|
|
|
|
|
{ |
26
|
51
|
|
|
51
|
1
|
33746
|
%context = (); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 NAME |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Context - request-local storage |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SYNOPSIS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$ctx = Pinwheel::Context::get(); |
37
|
|
|
|
|
|
|
$ctx = Pinwheel::Context::get('template'); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Pinwheel::Context::set(x => 'foo', y => 'bar', z => 42); |
40
|
|
|
|
|
|
|
Pinwheel::Context::set('template', foo => 'bar', baz => 'bal'); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Pinwheel::Context::reset(); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This module provides storage that can be completely emptied with a call to |
47
|
|
|
|
|
|
|
C. It is used by L to provide request-local storage for |
48
|
|
|
|
|
|
|
modules, and as the mechanism for sharing data between controllers and views. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Contexts are hashes (C returns a reference to a hash). Multiple contexts |
51
|
|
|
|
|
|
|
are supported by use of the optional NAMESPACE argument. Whenever NAMESPACE |
52
|
|
|
|
|
|
|
is omitted, it defaults to a value generated from the caller's package. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 ROUTINES |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=over 4 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item C or C |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Retrieves a context hash. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Examples: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $ctx = Pinwheel::Context::get(); |
65
|
|
|
|
|
|
|
return $ctx->{action}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
or |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $ctx = Pinwheel::Context::get('template'); |
70
|
|
|
|
|
|
|
return $ctx->{pagetitle}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item C or C |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Set one or more values in the context. The appropriate context is emptied, |
75
|
|
|
|
|
|
|
then filled with the given VALUES. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Examples: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Pinwheel::Context::set(x => 1, y => 42); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
or |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Pinwheel::Context::set('template', date => $date, message => $msg); |
84
|
|
|
|
|
|
|
Pinwheel::Context::set('template', schedule => $schedule); |
85
|
|
|
|
|
|
|
# 'date' and 'message' are now gone |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item C |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Clears all the context information in all namespaces. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
A&M Network Publishing |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |