X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fautovivification.git;a=blobdiff_plain;f=lib%2Fautovivification.pm;h=5eabf25c6965ca5a69d21ea836639ecc5560b423;hp=9ef999448b07a5fb61cac7a3c77879c7db65f6ef;hb=3b30e5cce1db5d76cf705f5b7b4f5c9fc4913a8a;hpb=98cae81d709fdc8b0f2aff8c6006a79f994f7b2c diff --git a/lib/autovivification.pm b/lib/autovivification.pm index 9ef9994..5eabf25 100644 --- a/lib/autovivification.pm +++ b/lib/autovivification.pm @@ -1,6 +1,6 @@ package autovivification; -use 5.008; +use 5.008003; use strict; use warnings; @@ -11,13 +11,13 @@ autovivification - Lexically disable autovivification. =head1 VERSION -Version 0.05 +Version 0.10 =cut our $VERSION; BEGIN { - $VERSION = '0.05'; + $VERSION = '0.10'; } =head1 SYNOPSIS @@ -55,7 +55,7 @@ BEGIN { =head2 C -Magically called when C is encountered. +Magically called when C is encountered. Enables the features given in C<@opts>, which can be : =over 4 @@ -64,48 +64,75 @@ Enables the features given in C<@opts>, which can be : C<'fetch'> -Turn off autovivification for rvalue dereferencing expressions, such as C<< $value = $hashref->{key}[$idx]{$field} >>, C<< keys %{$hashref->{key}} >> or C<< values %{$hashref->{key}} >>. -Starting from perl C<5.11>, it also covers C and C on array references. +Turns off autovivification for rvalue dereferencing expressions, such as : + + $value = $arrayref->[$idx] + $value = $hashref->{$key} + keys %$hashref + values %$hashref + +Starting from perl C<5.11>, it also covers C and C on array references : + + keys @$arrayref + values @$arrayref + When the expression would have autovivified, C is returned for a plain fetch, while C and C return C<0> in scalar context and the empty list in list context. =item * C<'exists'> -Turn off autovivification for dereferencing expressions that are parts of an C, such as C<< exists $hashref->{key}[$idx]{$field} >>. +Turns off autovivification for dereferencing expressions that are parts of an C, such as : + + exists $arrayref->[$idx] + exists $hashref->{$key} + C<''> is returned when the expression would have autovivified. =item * C<'delete'> -Turn off autovivification for dereferencing expressions that are parts of a C, such as C<< delete $hashref->{key}[$idx]{$field} >>. +Turns off autovivification for dereferencing expressions that are parts of a C, such as : + + delete $arrayref->[$idx] + delete $hashref->{$key} + C is returned when the expression would have autovivified. =item * C<'store'> -Turn off autovivification for lvalue dereferencing expressions, such as C<< $hashref->{key}[$idx]{$field} = $value >> or C<< for ($hashref->{key}[$idx]{$field}) { ... } >>. -An exception is thrown if vivification is needed to store the value, which means that effectively you can only assign to levels that are already defined (in the example, this would require C<< $hashref->{key}[$idx] >> to already be a hash reference). +Turns off autovivification for lvalue dereferencing expressions, such as : + + $arrayref->[$idx] = $value + $hashref->{$key} = $value + for ($arrayref->[$idx]) { ... } + for ($hashref->{$key}) { ... } + function($arrayref->[$idx]) + function($hashref->{$key}) + +An exception is thrown if vivification is needed to store the value, which means that effectively you can only assign to levels that are already defined. +In the example, this would require C<$arrayref> (resp. C<$hashref>) to already be an array (resp. hash) reference. =item * C<'warn'> -Emit a warning when an autovivification is avoided. +Emits a warning when an autovivification is avoided. =item * C<'strict'> -Throw an exception when an autovivification is avoided. +Throws an exception when an autovivification is avoided. =back Each call to C adds the specified features to the ones already in use in the current lexical scope. -When C<@opts> is empty, it defaults to C. +When C<@opts> is empty, it defaults to C<< qw >>. =cut @@ -121,7 +148,7 @@ my %bits = ( sub unimport { shift; my $hint = _detag($^H{+(__PACKAGE__)}) || 0; - @_ = qw/fetch exists delete/ unless @_; + @_ = qw unless @_; $hint |= $bits{$_} for grep exists $bits{$_}, @_; $^H |= 0x00020000; $^H{+(__PACKAGE__)} = _tag($hint); @@ -130,7 +157,7 @@ sub unimport { =head2 C -Magically called when C is encountered. +Magically called when C is encountered. Disables the features given in C<@opts>, which can be the same as for L. Each call to C removes the specified features to the ones already in use in the current lexical scope. @@ -161,7 +188,7 @@ This constant only has a meaning with your perl is threaded ; otherwise, it'll a =head2 C True iff this module could have been built with fork-safety features enabled. -This will always be true except on Windows where it's false for perl 5.10.0 and below . +This will always be true except on Windows where it's false for perl 5.10.0 and below. =head1 CAVEATS @@ -171,7 +198,10 @@ If warnings are turned on, Perl will complain about one-element slices. =head1 DEPENDENCIES -L 5.8. +L 5.8.3. + +A C compiler. +This module may happen to build with a C++ compiler as well, but don't rely on it, as no guarantee is made in this regard. L (standard since perl 5.006). @@ -204,7 +234,7 @@ Matt S. Trout asked for it. =head1 COPYRIGHT & LICENSE -Copyright 2009,2010 Vincent Pit, all rights reserved. +Copyright 2009,2010,2011 Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.