README
1NAME
2 Lexical::Persistence - Persistent lexical variable values for arbitrary
3 calls.
4
5VERSION
6 version 1.023
7
8SYNOPSIS
9 #!/usr/bin/perl
10
11 use Lexical::Persistence;
12
13 my $persistence = Lexical::Persistence->new();
14 foreach my $number (qw(one two three four five)) {
15 $persistence->call(\&target, number => $number);
16 }
17
18 exit;
19
20 sub target {
21 my $arg_number; # Argument.
22 my $narf_x++; # Persistent.
23 my $_i++; # Dynamic.
24 my $j++; # Persistent.
25
26 print "arg_number = $arg_number\n";
27 print "\tnarf_x = $narf_x\n";
28 print "\t_i = $_i\n";
29 print "\tj = $j\n";
30 }
31
32DESCRIPTION
33 Lexical::Persistence does a few things, all related. Note that all the
34 behaviors listed here are the defaults. Subclasses can override nearly
35 every aspect of Lexical::Persistence's behavior.
36
37 Lexical::Persistence lets your code access persistent data through
38 lexical variables. This example prints "some value" because the value of
39 $x persists in the $lp object between setter() and getter().
40
41 use Lexical::Persistence;
42
43 my $lp = Lexical::Persistence->new();
44 $lp->call(\&setter);
45 $lp->call(\&getter);
46
47 sub setter { my $x = "some value" }
48 sub getter { print my $x, "\n" }
49
50 Lexicals with leading underscores are not persistent.
51
52 By default, Lexical::Persistence supports accessing data from multiple
53 sources through the use of variable prefixes. The set_context() member
54 sets each data source. It takes a prefix name and a hash of key/value
55 pairs. By default, the keys must have sigils representing their variable
56 types.
57
58 use Lexical::Persistence;
59
60 my $lp = Lexical::Persistence->new();
61 $lp->set_context( pi => { '$member' => 3.141 } );
62 $lp->set_context( e => { '@member' => [ 2, '.', 7, 1, 8 ] } );
63 $lp->set_context(
64 animal => {
65 '%member' => { cat => "meow", dog => "woof" }
66 }
67 );
68
69 $lp->call(\&display);
70
71 sub display {
72 my ($pi_member, @e_member, %animal_member);
73
74 print "pi = $pi_member\n";
75 print "e = @e_member\n";
76 while (my ($animal, $sound) = each %animal_member) {
77 print "The $animal goes... $sound!\n";
78 }
79 }
80
81 And the corresponding output:
82
83 pi = 3.141
84 e = 2 . 7 1 8
85 The cat goes... meow!
86 The dog goes... woof!
87
88 By default, call() takes a single subroutine reference and an optional
89 list of named arguments. The arguments will be passed directly to the
90 called subroutine, but Lexical::Persistence also makes the values
91 available from the "arg" prefix.
92
93 use Lexical::Persistence;
94
95 my %animals = (
96 snake => "hiss",
97 plane => "I'm Cartesian",
98 );
99
100 my $lp = Lexical::Persistence->new();
101 while (my ($animal, $sound) = each %animals) {
102 $lp->call(\&display, animal => $animal, sound => $sound);
103 }
104
105 sub display {
106 my ($arg_animal, $arg_sound);
107 print "The $arg_animal goes... $arg_sound!\n";
108 }
109
110 And the corresponding output:
111
112 The plane goes... I'm Cartesian!
113 The snake goes... hiss!
114
115 Sometimes you want to call functions normally. The wrap() method will
116 wrap your function in a small thunk that does the call() for you,
117 returning a coderef.
118
119 use Lexical::Persistence;
120
121 my $lp = Lexical::Persistence->new();
122 my $thunk = $lp->wrap(\&display);
123
124 $thunk->(animal => "squirrel", sound => "nuts");
125
126 sub display {
127 my ($arg_animal, $arg_sound);
128 print "The $arg_animal goes... $arg_sound!\n";
129 }
130
131 And the corresponding output:
132
133 The squirrel goes... nuts!
134
135 Prefixes are the characters leading up to the first underscore in a
136 lexical variable's name. However, there's also a default context named
137 underscore. It's literally "_" because the underscore is not legal in a
138 context name by default. Variables without prefixes, or with prefixes
139 that have not been previously defined by set_context(), are stored in
140 that context.
141
142 The get_context() member returns a hash for a named context. This allows
143 your code to manipulate the values within a persistent context.
144
145 use Lexical::Persistence;
146
147 my $lp = Lexical::Persistence->new();
148 $lp->set_context(
149 _ => {
150 '@mind' => [qw(My mind is going. I can feel it.)]
151 }
152 );
153
154 while (1) {
155 $lp->call(\&display);
156 my $mind = $lp->get_context("_")->{'@mind'};
157 splice @$mind, rand(@$mind), 1;
158 last unless @$mind;
159 }
160
161 sub display {
162 my @mind;
163 print "@mind\n";
164 }
165
166 Displays something like:
167
168 My mind is going. I can feel it.
169 My is going. I can feel it.
170 My is going. I feel it.
171 My going. I feel it.
172 My going. I feel
173 My I feel
174 My I
175 My
176
177 It's possible to create multiple Lexical::Persistence objects, each with
178 a unique state.
179
180 use Lexical::Persistence;
181
182 my $lp_1 = Lexical::Persistence->new();
183 $lp_1->set_context( _ => { '$foo' => "context 1's foo" } );
184
185 my $lp_2 = Lexical::Persistence->new();
186 $lp_2->set_context( _ => { '$foo' => "the foo in context 2" } );
187
188 $lp_1->call(\&display);
189 $lp_2->call(\&display);
190
191 sub display {
192 print my $foo, "\n";
193 }
194
195 Gets you this output:
196
197 context 1's foo
198 the foo in context 2
199
200 You can also compile and execute perl code contained in plain strings in
201 a a lexical environment that already contains the persisted variables.
202
203 use Lexical::Persistence;
204
205 my $lp = Lexical::Persistence->new();
206
207 $lp->do( 'my $message = "Hello, world" );
208
209 $lp->do( 'print "$message\n"' );
210
211 Which gives the output:
212
213 Hello, world
214
215 If you come up with other fun uses, let us know.
216
217 new
218 Create a new lexical persistence object. This object will store one or
219 more persistent contexts. When called by this object, lexical variables
220 will take on the values kept in this object.
221
222 initialize_contexts
223 This method is called by new() to declare the initial contexts for a new
224 Lexical::Persistence object. The default implementation declares the
225 default "_" context.
226
227 Override or extend it to create others as needed.
228
229 set_context NAME, HASH
230 Store a context HASH within the persistence object, keyed on a NAME.
231 Members of the context HASH are unprefixed versions of the lexicals
232 they'll persist, including the sigil. For example, this set_context()
233 call declares a "request" context with predefined values for three
234 variables: $request_foo, @request_foo, and %request_foo:
235
236 $lp->set_context(
237 request => {
238 '$foo' => 'value of $request_foo',
239 '@foo' => [qw( value of @request_foo )],
240 '%foo' => { key => 'value of $request_foo{key}' }
241 }
242 );
243
244 See parse_variable() for information about how Lexical::Persistence
245 decides which context a lexical belongs to and how you can change that.
246
247 get_context NAME
248 Returns a context hash associated with a particular context name.
249 Autovivifies the context if it doesn't already exist, so be careful
250 there.
251
252 call CODEREF, ARGUMENT_LIST
253 Call CODEREF with lexical persistence and an optional ARGUMENT_LIST,
254 consisting of name => value pairs. Unlike with set_context(), however,
255 argument names do not need sigils. This may change in the future,
256 however, as it's easy to access an argument with the wrong variable
257 type.
258
259 The ARGUMENT_LIST is passed to the called CODEREF through @_ in the
260 usual way. They're also available as $arg_name variables for
261 convenience.
262
263 See push_arg_context() for information about how $arg_name works, and
264 what you can do to change that behavior.
265
266 invoke OBJECT, METHOD, ARGUMENT_LIST
267 Invoke OBJECT->METHOD(ARGUMENT_LIST) while maintaining state for the
268 METHOD's lexical variables. Written in terms of call(), except that it
269 takes OBJECT and METHOD rather than CODEREF. See call() for more
270 details.
271
272 May have issues with methods invoked via AUTOLOAD, as invoke() uses
273 can() to find the method's CODEREF for call().
274
275 wrap CODEREF
276 Wrap a function or anonymous CODEREF so that it's transparently called
277 via call(). Returns a coderef which can be called directly. Named
278 arguments to the call will automatically become available as $arg_name
279 lexicals within the called CODEREF.
280
281 See call() and push_arg_context() for more details.
282
283 prepare CODE
284 Wrap a CODE string in a subroutine definition, and prepend declarations
285 for all the variables stored in the Lexical::Persistence default
286 context. This avoids having to declare variables explicitly in the code
287 using 'my'. Returns a new code string ready for Perl's built-in eval().
288 From there, a program may $lp->call() the code or $lp->wrap() it.
289
290 Also see "compile()", which is a convenient wrapper for prepare() and
291 Perl's built-in eval().
292
293 Also see "do()", which is a convenient way to prepare(), eval() and
294 call() in one step.
295
296 compile CODE
297 compile() is a convenience method to prepare() a CODE string, eval() it,
298 and then return the resulting coderef. If it fails, it returns false,
299 and $@ will explain why.
300
301 do CODE
302 do() is a convenience method to compile() a CODE string and execute it.
303 It returns the result of CODE's execution, or it throws an exception on
304 failure.
305
306 This example prints the numbers 1 through 10. Note, however, that do()
307 compiles the same code each time.
308
309 use Lexical::Persistence;
310
311 my $lp = Lexical::Persistence->new();
312 $lp->do('my $count = 0');
313 $lp->do('print ++$count, "\\n"') for 1..10;
314
315 Lexical declarations are preserved across do() invocations, such as with
316 $count in the surrounding examples. This behavior is part of prepare(),
317 which do() uses via compile().
318
319 The previous example may be rewritten in terms of compile() and call()
320 to avoid recompiling code every iteration. Lexical declarations are
321 preserved between do() and compile() as well:
322
323 use Lexical::Persistence;
324
325 my $lp = Lexical::Persistence->new();
326 $lp->do('my $count = 0');
327 my $coderef = $lp->compile('print ++$count, "\\n"');
328 $lp->call($coderef) for 1..10;
329
330 do() inherits some limitations from PadWalker's peek_sub(). For
331 instance, it cannot alias lexicals within sub() definitions in the
332 supplied CODE string. However, Lexical::Persistence can do this with
333 careful use of eval() and some custom CODE preparation.
334
335 parse_variable VARIABLE_NAME
336 This method determines whether VARIABLE_NAME should be persistent. If it
337 should, parse_variable() will return three values: the variable's sigil
338 ('$', '@' or '%'), the context name in which the variable persists (see
339 set_context()), and the name of the member within that context where the
340 value is stored. parse_variable() returns nothing if VARIABLE_NAME
341 should not be persistent.
342
343 parse_variable() also determines whether the member name includes its
344 sigil. By default, the "arg" context is the only one with members that
345 have no sigils. This is done to support the unadorned argument names
346 used by call().
347
348 This method implements a default behavior. It's intended to be
349 overridden or extended by subclasses.
350
351 get_member_ref SIGIL, CONTEXT, MEMBER
352 This method fetches a reference to the named MEMBER of a particular
353 named CONTEXT. The returned value type will be governed by the given
354 SIGIL.
355
356 Scalar values are stored internally as scalars to be consistent with how
357 most people store scalars.
358
359 The persistent value is created if it doesn't exist. The initial value
360 is undef or empty, depending on its type.
361
362 This method implements a default behavior. It's intended to be
363 overridden or extended by subclasses.
364
365 push_arg_context ARGUMENT_LIST
366 Convert a named ARGUMENT_LIST into members of an argument context, and
367 call set_context() to declare that context. This is how $arg_foo
368 variables are supported. This method returns the previous context,
369 fetched by get_context() before the new context is set.
370
371 This method implements a default behavior. It's intended to be
372 overridden or extended by subclasses. For example, to redefine the
373 parameters as $param_foo.
374
375 See pop_arg_context() for the other side of this coin.
376
377 pop_arg_context OLD_ARG_CONTEXT
378 Restores OLD_ARG_CONTEXT after a target function has returned. The
379 OLD_ARG_CONTEXT is the return value from the push_arg_context() call
380 just prior to the target function's call.
381
382 This method implements a default behavior. It's intended to be
383 overridden or extended by subclasses.
384
385SEE ALSO
386 POE::Stage, Devel::LexAlias, PadWalker, Catalyst::Controller::BindLex.
387
388 BUG TRACKER
389 https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=Lexical-Persis
390 tence
391
392 REPOSITORY
393 http://github.com/rcaputo/lexical-persistence
394 http://gitorious.org/lexical-persistence
395
396 OTHER RESOURCES
397 http://search.cpan.org/dist/Lexical-Persistence/
398
399COPYRIGHT
400 Lexical::Persistence in copyright 2006-2013 by Rocco Caputo. All rights
401 reserved. Lexical::Persistence is free software. It is released under
402 the same terms as Perl itself.
403
404ACKNOWLEDGEMENTS
405 Thanks to Matt Trout and Yuval Kogman for lots of inspiration. They were
406 the demon and the other demon sitting on my shoulders.
407
408 Nick Perez convinced me to make this a class rather than persist with
409 the original, functional design. While Higher Order Perl is fun for
410 development, I have to say the move to OO was a good one.
411
412 Paul "LeoNerd" Evans contributed the compile() and eval() methods.
413
414 The South Florida Perl Mongers, especially Jeff Bisbee and Marlon
415 Bailey, for documentation feedback.
416
417 irc://irc.perl.org/poe for support and feedback.
418
419
README.mkdn
1# NAME
2
3Lexical::Persistence - Persistent lexical variable values for arbitrary calls.
4
5# VERSION
6
7version 1.023
8
9# SYNOPSIS
10
11 #!/usr/bin/perl
12
13 use Lexical::Persistence;
14
15 my $persistence = Lexical::Persistence->new();
16 foreach my $number (qw(one two three four five)) {
17 $persistence->call(\&target, number => $number);
18 }
19
20 exit;
21
22 sub target {
23 my $arg_number; # Argument.
24 my $narf_x++; # Persistent.
25 my $_i++; # Dynamic.
26 my $j++; # Persistent.
27
28 print "arg_number = $arg_number\n";
29 print "\tnarf_x = $narf_x\n";
30 print "\t_i = $_i\n";
31 print "\tj = $j\n";
32 }
33
34# DESCRIPTION
35
36Lexical::Persistence does a few things, all related. Note that all
37the behaviors listed here are the defaults. Subclasses can override
38nearly every aspect of Lexical::Persistence's behavior.
39
40Lexical::Persistence lets your code access persistent data through
41lexical variables. This example prints "some value" because the value
42of $x persists in the $lp object between setter() and getter().
43
44 use Lexical::Persistence;
45
46 my $lp = Lexical::Persistence->new();
47 $lp->call(\&setter);
48 $lp->call(\&getter);
49
50 sub setter { my $x = "some value" }
51 sub getter { print my $x, "\n" }
52
53Lexicals with leading underscores are not persistent.
54
55By default, Lexical::Persistence supports accessing data from multiple
56sources through the use of variable prefixes. The set\_context()
57member sets each data source. It takes a prefix name and a hash of
58key/value pairs. By default, the keys must have sigils representing
59their variable types.
60
61 use Lexical::Persistence;
62
63 my $lp = Lexical::Persistence->new();
64 $lp->set_context( pi => { '$member' => 3.141 } );
65 $lp->set_context( e => { '@member' => [ 2, '.', 7, 1, 8 ] } );
66 $lp->set_context(
67 animal => {
68 '%member' => { cat => "meow", dog => "woof" }
69 }
70 );
71
72 $lp->call(\&display);
73
74 sub display {
75 my ($pi_member, @e_member, %animal_member);
76
77 print "pi = $pi_member\n";
78 print "e = @e_member\n";
79 while (my ($animal, $sound) = each %animal_member) {
80 print "The $animal goes... $sound!\n";
81 }
82 }
83
84And the corresponding output:
85
86 pi = 3.141
87 e = 2 . 7 1 8
88 The cat goes... meow!
89 The dog goes... woof!
90
91By default, call() takes a single subroutine reference and an optional
92list of named arguments. The arguments will be passed directly to the
93called subroutine, but Lexical::Persistence also makes the values
94available from the "arg" prefix.
95
96 use Lexical::Persistence;
97
98 my %animals = (
99 snake => "hiss",
100 plane => "I'm Cartesian",
101 );
102
103 my $lp = Lexical::Persistence->new();
104 while (my ($animal, $sound) = each %animals) {
105 $lp->call(\&display, animal => $animal, sound => $sound);
106 }
107
108 sub display {
109 my ($arg_animal, $arg_sound);
110 print "The $arg_animal goes... $arg_sound!\n";
111 }
112
113And the corresponding output:
114
115 The plane goes... I'm Cartesian!
116 The snake goes... hiss!
117
118Sometimes you want to call functions normally. The wrap() method will
119wrap your function in a small thunk that does the call() for you,
120returning a coderef.
121
122 use Lexical::Persistence;
123
124 my $lp = Lexical::Persistence->new();
125 my $thunk = $lp->wrap(\&display);
126
127 $thunk->(animal => "squirrel", sound => "nuts");
128
129 sub display {
130 my ($arg_animal, $arg_sound);
131 print "The $arg_animal goes... $arg_sound!\n";
132 }
133
134And the corresponding output:
135
136 The squirrel goes... nuts!
137
138Prefixes are the characters leading up to the first underscore in a
139lexical variable's name. However, there's also a default context
140named underscore. It's literally "\_" because the underscore is not
141legal in a context name by default. Variables without prefixes, or
142with prefixes that have not been previously defined by set\_context(),
143are stored in that context.
144
145The get\_context() member returns a hash for a named context. This
146allows your code to manipulate the values within a persistent context.
147
148 use Lexical::Persistence;
149
150 my $lp = Lexical::Persistence->new();
151 $lp->set_context(
152 _ => {
153 '@mind' => [qw(My mind is going. I can feel it.)]
154 }
155 );
156
157 while (1) {
158 $lp->call(\&display);
159 my $mind = $lp->get_context("_")->{'@mind'};
160 splice @$mind, rand(@$mind), 1;
161 last unless @$mind;
162 }
163
164 sub display {
165 my @mind;
166 print "@mind\n";
167 }
168
169Displays something like:
170
171 My mind is going. I can feel it.
172 My is going. I can feel it.
173 My is going. I feel it.
174 My going. I feel it.
175 My going. I feel
176 My I feel
177 My I
178 My
179
180It's possible to create multiple Lexical::Persistence objects, each
181with a unique state.
182
183 use Lexical::Persistence;
184
185 my $lp_1 = Lexical::Persistence->new();
186 $lp_1->set_context( _ => { '$foo' => "context 1's foo" } );
187
188 my $lp_2 = Lexical::Persistence->new();
189 $lp_2->set_context( _ => { '$foo' => "the foo in context 2" } );
190
191 $lp_1->call(\&display);
192 $lp_2->call(\&display);
193
194 sub display {
195 print my $foo, "\n";
196 }
197
198Gets you this output:
199
200 context 1's foo
201 the foo in context 2
202
203You can also compile and execute perl code contained in plain strings in a
204a lexical environment that already contains the persisted variables.
205
206 use Lexical::Persistence;
207
208 my $lp = Lexical::Persistence->new();
209
210 $lp->do( 'my $message = "Hello, world" );
211
212 $lp->do( 'print "$message\n"' );
213
214Which gives the output:
215
216 Hello, world
217
218If you come up with other fun uses, let us know.
219
220## new
221
222Create a new lexical persistence object. This object will store one
223or more persistent contexts. When called by this object, lexical
224variables will take on the values kept in this object.
225
226## initialize\_contexts
227
228This method is called by new() to declare the initial contexts for a
229new Lexical::Persistence object. The default implementation declares
230the default "\_" context.
231
232Override or extend it to create others as needed.
233
234## set\_context NAME, HASH
235
236Store a context HASH within the persistence object, keyed on a NAME.
237Members of the context HASH are unprefixed versions of the lexicals
238they'll persist, including the sigil. For example, this set\_context()
239call declares a "request" context with predefined values for three
240variables: $request\_foo, @request\_foo, and %request\_foo:
241
242 $lp->set_context(
243 request => {
244 '$foo' => 'value of $request_foo',
245 '@foo' => [qw( value of @request_foo )],
246 '%foo' => { key => 'value of $request_foo{key}' }
247 }
248 );
249
250See parse\_variable() for information about how Lexical::Persistence
251decides which context a lexical belongs to and how you can change
252that.
253
254## get\_context NAME
255
256Returns a context hash associated with a particular context name.
257Autovivifies the context if it doesn't already exist, so be careful
258there.
259
260## call CODEREF, ARGUMENT\_LIST
261
262Call CODEREF with lexical persistence and an optional ARGUMENT\_LIST,
263consisting of name => value pairs. Unlike with set\_context(),
264however, argument names do not need sigils. This may change in the
265future, however, as it's easy to access an argument with the wrong
266variable type.
267
268The ARGUMENT\_LIST is passed to the called CODEREF through @\_ in the
269usual way. They're also available as $arg\_name variables for
270convenience.
271
272See push\_arg\_context() for information about how $arg\_name works, and
273what you can do to change that behavior.
274
275## invoke OBJECT, METHOD, ARGUMENT\_LIST
276
277Invoke OBJECT->METHOD(ARGUMENT\_LIST) while maintaining state for the
278METHOD's lexical variables. Written in terms of call(), except that
279it takes OBJECT and METHOD rather than CODEREF. See call() for more
280details.
281
282May have issues with methods invoked via AUTOLOAD, as invoke() uses
283can() to find the method's CODEREF for call().
284
285## wrap CODEREF
286
287Wrap a function or anonymous CODEREF so that it's transparently called
288via call(). Returns a coderef which can be called directly. Named
289arguments to the call will automatically become available as $arg\_name
290lexicals within the called CODEREF.
291
292See call() and push\_arg\_context() for more details.
293
294## prepare CODE
295
296Wrap a CODE string in a subroutine definition, and prepend
297declarations for all the variables stored in the Lexical::Persistence
298default context. This avoids having to declare variables explicitly
299in the code using 'my'. Returns a new code string ready for Perl's
300built-in eval(). From there, a program may $lp->call() the code or
301$lp->wrap() it.
302
303Also see ["compile()"](#compile()), which is a convenient wrapper for prepare()
304and Perl's built-in eval().
305
306Also see ["do()"](#do()), which is a convenient way to prepare(), eval() and
307call() in one step.
308
309## compile CODE
310
311compile() is a convenience method to prepare() a CODE string, eval()
312it, and then return the resulting coderef. If it fails, it returns
313false, and $@ will explain why.
314
315## do CODE
316
317do() is a convenience method to compile() a CODE string and execute
318it. It returns the result of CODE's execution, or it throws an
319exception on failure.
320
321This example prints the numbers 1 through 10. Note, however, that
322do() compiles the same code each time.
323
324 use Lexical::Persistence;
325
326 my $lp = Lexical::Persistence->new();
327 $lp->do('my $count = 0');
328 $lp->do('print ++$count, "\\n"') for 1..10;
329
330Lexical declarations are preserved across do() invocations, such as
331with $count in the surrounding examples. This behavior is part of
332prepare(), which do() uses via compile().
333
334The previous example may be rewritten in terms of compile() and call()
335to avoid recompiling code every iteration. Lexical declarations are
336preserved between do() and compile() as well:
337
338 use Lexical::Persistence;
339
340 my $lp = Lexical::Persistence->new();
341 $lp->do('my $count = 0');
342 my $coderef = $lp->compile('print ++$count, "\\n"');
343 $lp->call($coderef) for 1..10;
344
345do() inherits some limitations from PadWalker's peek\_sub(). For
346instance, it cannot alias lexicals within sub() definitions in the
347supplied CODE string. However, Lexical::Persistence can do this with
348careful use of eval() and some custom CODE preparation.
349
350## parse\_variable VARIABLE\_NAME
351
352This method determines whether VARIABLE\_NAME should be persistent. If
353it should, parse\_variable() will return three values: the variable's
354sigil ('$', '@' or '%'), the context name in which the variable
355persists (see set\_context()), and the name of the member within that
356context where the value is stored. parse\_variable() returns nothing
357if VARIABLE\_NAME should not be persistent.
358
359parse\_variable() also determines whether the member name includes its
360sigil. By default, the "arg" context is the only one with members
361that have no sigils. This is done to support the unadorned argument
362names used by call().
363
364This method implements a default behavior. It's intended to be
365overridden or extended by subclasses.
366
367## get\_member\_ref SIGIL, CONTEXT, MEMBER
368
369This method fetches a reference to the named MEMBER of a particular
370named CONTEXT. The returned value type will be governed by the given
371SIGIL.
372
373Scalar values are stored internally as scalars to be consistent with
374how most people store scalars.
375
376The persistent value is created if it doesn't exist. The initial
377value is undef or empty, depending on its type.
378
379This method implements a default behavior. It's intended to be
380overridden or extended by subclasses.
381
382## push\_arg\_context ARGUMENT\_LIST
383
384Convert a named ARGUMENT\_LIST into members of an argument context, and
385call set\_context() to declare that context. This is how $arg\_foo
386variables are supported. This method returns the previous context,
387fetched by get\_context() before the new context is set.
388
389This method implements a default behavior. It's intended to be
390overridden or extended by subclasses. For example, to redefine the
391parameters as $param\_foo.
392
393See pop\_arg\_context() for the other side of this coin.
394
395## pop\_arg\_context OLD\_ARG\_CONTEXT
396
397Restores OLD\_ARG\_CONTEXT after a target function has returned. The
398OLD\_ARG\_CONTEXT is the return value from the push\_arg\_context() call
399just prior to the target function's call.
400
401This method implements a default behavior. It's intended to be
402overridden or extended by subclasses.
403
404# SEE ALSO
405
406[POE::Stage](http://search.cpan.org/perldoc?POE::Stage), [Devel::LexAlias](http://search.cpan.org/perldoc?Devel::LexAlias), [PadWalker](http://search.cpan.org/perldoc?PadWalker),
407[Catalyst::Controller::BindLex](http://search.cpan.org/perldoc?Catalyst::Controller::BindLex).
408
409## BUG TRACKER
410
411https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=Lexical-Persistence
412
413## REPOSITORY
414
415http://github.com/rcaputo/lexical-persistence
416http://gitorious.org/lexical-persistence
417
418## OTHER RESOURCES
419
420http://search.cpan.org/dist/Lexical-Persistence/
421
422# COPYRIGHT
423
424Lexical::Persistence in copyright 2006-2013 by Rocco Caputo. All
425rights reserved. Lexical::Persistence is free software. It is
426released under the same terms as Perl itself.
427
428# ACKNOWLEDGEMENTS
429
430Thanks to Matt Trout and Yuval Kogman for lots of inspiration. They
431were the demon and the other demon sitting on my shoulders.
432
433Nick Perez convinced me to make this a class rather than persist with
434the original, functional design. While Higher Order Perl is fun for
435development, I have to say the move to OO was a good one.
436
437Paul "LeoNerd" Evans contributed the compile() and eval() methods.
438
439The South Florida Perl Mongers, especially Jeff Bisbee and Marlon
440Bailey, for documentation feedback.
441
442irc://irc.perl.org/poe for support and feedback.
443