From: Vincent Pit Date: Wed, 1 Apr 2015 22:55:29 +0000 (-0300) Subject: This is 0.02 X-Git-Tag: v0.02^0 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=534cf1851c05562fd6f604e8f788a0e58a4ede24;p=perl%2Fmodules%2FVariable-Temp.git This is 0.02 --- diff --git a/Changes b/Changes index 80f4cab..c11a2e5 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,13 @@ Revision history for Variable-Temp +0.02 2015-04-01 22:55 UTC + + Add : temp() can now be applied to arrays and hashes. + + Add : The new set_temp() function is a non-lvalue alternative to + temp(). In particular, it can be used on perl 5.12.x and + below. + + Fix : 'temp $var;' now correctly sets $var to undef. + + Fix : The tests now pass correctly on perl 5.12.x and below. + 0.01 2015-03-09 13:55 UTC First version, released on an unsuspecting world. diff --git a/META.json b/META.json index 9f69490..ca6a384 100644 --- a/META.json +++ b/META.json @@ -4,7 +4,7 @@ "Vincent Pit " ], "dynamic_config" : 0, - "generated_by" : "ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.143240", + "generated_by" : "ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.150001", "license" : [ "perl_5" ], @@ -26,7 +26,9 @@ "ExtUtils::MakeMaker" : "0", "Scope::Upper" : "0", "Test::More" : "0", - "base" : "0" + "Variable::Magic" : "0.51", + "base" : "0", + "lib" : "0" } }, "configure" : { @@ -39,6 +41,7 @@ "Exporter" : "0", "Scope::Upper" : "0", "Test::More" : "0", + "Variable::Magic" : "0.51", "base" : "0", "perl" : "5.006" } @@ -57,5 +60,5 @@ "url" : "http://git.profvince.com/?p=perl%2Fmodules%2FVariable-Temp.git" } }, - "version" : "0.01" + "version" : "0.02" } diff --git a/META.yml b/META.yml index adf966f..086f853 100644 --- a/META.yml +++ b/META.yml @@ -7,11 +7,13 @@ build_requires: ExtUtils::MakeMaker: '0' Scope::Upper: '0' Test::More: '0' + Variable::Magic: '0.51' base: '0' + lib: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 -generated_by: 'ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.143240' +generated_by: 'ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.150001' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -25,6 +27,7 @@ requires: Exporter: '0' Scope::Upper: '0' Test::More: '0' + Variable::Magic: '0.51' base: '0' perl: '5.006' resources: @@ -32,4 +35,4 @@ resources: homepage: http://search.cpan.org/dist/Variable-Temp/ license: http://dev.perl.org/licenses/ repository: http://git.profvince.com/?p=perl%2Fmodules%2FVariable-Temp.git -version: '0.01' +version: '0.02' diff --git a/README b/README index 276fff6..df6d397 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME Variable::Temp - Temporarily change the value of a variable. VERSION - Version 0.01 + Version 0.02 SYNOPSIS use Variable::Temp 'temp'; @@ -17,43 +17,68 @@ SYNOPSIS DESCRIPTION This module provides an utility routine that can be used to temporarily - change the value of a variable, until the end of the current scope is - reached where the original value of the variable is restored. It is - similar to "local", except that it can be applied onto lexicals as well - as globals, and that it replaces values by copying the new value into - the container variable instead of by aliasing. + change the value of a scalar, array or hash variable, until the end of + the current scope is reached where the original value of the variable is + restored. It is similar to "local", except that it can be applied onto + lexicals as well as globals, and that it replaces values by copying the + new value into the container variable instead of by aliasing. FUNCTIONS "temp" temp $var; temp $var = $value; - Temporarily replace the value of the lexical or global variable $var by - $value, or by "undef" if $value is omitted, until the end of the current - scope. Any subsequent assignments to $var in the current (or any - inferior) scope will not affect the original value which will be - restored into the variable at scope end. Several "temp" calls can be - made onto the same variable, and the restore are processed in reverse - order. + temp @var; + temp @var = \@value; - Note that destructors associated with $var will not be called when - "temp" sets the temporary value, but only at the natural end of life of - the variable (i.e. at the end of the scope). They will trigger after any - destructor associated with the replacement $var. + temp %var; + temp %var = \%value; -EXPORT - The function "temp" is only exported on request by passing 'temp' to the - module import list. + Temporarily replaces the value of the lexical or global variable $var by + $value (respectively @var by @value, %var by %value), or by "undef" if + $value is omitted (respectively empties @var and %var if the second + argument is omitted), until the end of the current scope. Any subsequent + assignments to this variable in the current (or any inferior) scope will + not affect the original value which will be restored into the variable + at scope end. Several "temp" calls can be made onto the same variable, + and the restore are processed in reverse order. + + Note that destructors associated with the variable will not be called + when "temp" sets the temporary value, but only at the natural end of + life of the variable. They will trigger after any destructor associated + with the replacement value. + + Due to a shortcoming in the handling of the "\$" prototype, which was + addressed in "perl" 5.14, the pseudo-statement "temp $var = $value" will + cause compilation errors on "perl" 5.12.x and below. If you want your + code to run on these versions of "perl", you are encouraged to use + "set_temp" instead. + + "set_temp" + set_temp $var; + set_temp $var => $value; + + set_temp @var; + set_temp @var => \@value; + + set_temp %var; + set_temp %var => \%value; -CAVEATS - Currently only applies to scalar variables. + A non-lvalue variant of "temp" that can be used with any version of + "perl". + +EXPORT + The functions "temp" and "set_temp" are only exported on request by + specifying their names in the module import list. DEPENDENCIES perl 5.6. + Exporter (core since perl 5). + Scope::Upper. - Exporter (core since perl 5). + Variable::Magic 0.51. SEE ALSO Scope::Upper. diff --git a/lib/Variable/Temp.pm b/lib/Variable/Temp.pm index 390ff48..7477711 100644 --- a/lib/Variable/Temp.pm +++ b/lib/Variable/Temp.pm @@ -11,13 +11,13 @@ Variable::Temp - Temporarily change the value of a variable. =head1 VERSION -Version 0.01 +Version 0.02 =cut our $VERSION; BEGIN { - $VERSION = '0.01'; + $VERSION = '0.02'; } =head1 SYNOPSIS