Data::Postponed::OnceOnly - Put off computing a value as long as possible but throw errors if later changes are attempted
Example using postpone()
use Data::Postponed 'postpone'; %functions = ( foobar => 'foo' ); $code = "sub " . postpone( $functions{foobar} ) . " { return time }"; $functions{foobar} = "baz"; # Reflects the new name of 'bar' instead of 'foo'. $code isn't # overloaded anymore. print $code; # This line is now an error because $functions{foobar} is readonly. $functions{foobar} = "quux"; # This line isn't reached. print $code;
Example using the OO
use Data::Postponed; %functions = ( foobar => 'foo' ); $code = "sub " . Data::Postpone::OnceOnly->new( $functions{foobar} ) . " { return time }"; $functions{foobar} = "baz"; # Reflects the new name of 'bar' instead of 'foo'; print $code; # This line is now an error because $functions{foobar} is readonly. $functions{foobar} = "quux"; # This line isn't reached. print $code;
The value of expressions that have had postpone called on them are in flux until finalized. Once finalized, they are no longer overloaded and any input variables used to compute the expression are changed to be readonly.
This will cause your program to throw errors if you attempt to modify something that has already been used to finalize something. That's the point. If you don't want that, use the Data::Postponed::Once manpage instead. It is identical except that it won't mark your variables as read only.
Returns a new overloaded object bound to whatever was passed in as the EXPR.
"", 0+, bool
Each of these methods are overridden from the Data::Postponed manpage. If you
wished to only finalize strings, you might just copy the "" and
new methods to your own subclass of the Data::Postponed manpage.
the Data::Postponed manpage, the Data::Postponed::Once manpage, the Data::Postponed::Forever manpage, the overload manpage
This is inspired by what I originally thought the Quantum::Superpositions manpage did. Here, the idea is that a value's actual value is in flux until it is examined hard enough and then is a real value.
This module is used in the B::Deobfuscate manpage to turn a two pass algorithm into a single pass. I would have had to do a complete run to get a final symbol table and then run it again to actually use the symbol table. This module allows me to change my mind about the values I've returned.
Joshua ben Jore, <jjore@cpan.org>
Please report any bugs or feature requests to
bug-data-postponed@rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html. I
will be notified, and then you'll automatically be notified of
progress on your bug as I make changes.
Corion of perlmonks.org
Copyright 2005 Joshua ben Jore, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.