Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into issue/235

Conflicts:
	META.json
	META.yml
  • Loading branch information...
commit 7c63a197159675e997645c6bc73a12fdd72936a0 2 parents 5a35018 + a74f0bc
@schwern schwern authored
View
3  Build.PL
@@ -12,7 +12,7 @@ my $builder = MyBuild->new(
module_name => 'perl5i',
license => 'perl',
dist_author => 'Michael G Schwern <schwern@pobox.com>',
- dist_version => "v2.10.0",
+ dist_version => "v2.11.0",
requires => {
'perl' => '5.10.0',
@@ -51,6 +51,7 @@ my $builder = MyBuild->new(
'Capture::Tiny' => '0.06',
'utf8::all' => '0.002',
'Carp::Fix::1_25' => '1.000000',
+ 'Hash::StoredIterator' => '0.001',
},
build_requires => {
'ExtUtils::CBuilder' => '0.26',
View
17 Changes
@@ -1,3 +1,20 @@
+2.11.0
+ Bug Fixes
+ * %hash->each({...}) iterator now uses Hash::StoredIterator
+ to ensure that it's safe to nest calls to each(), and to use
+ keys() and values() inside each() (Chad Granum)
+
+ Test Fixes
+ * Added new test template (Michael G. Schwern)
+
+ New Features
+ * ->mo->yaml and ->mo->json now allow you to dump a
+ meta-object as yaml or json respectively [github #230] (Ben
+ Hengst)
+
+ Misc
+ * Fixed examples in the documentation (Tom Legrady)
+
2.10.0 Sat Jul 7 11:57:01 PDT 2012
Bug Fixes
* Upgraded autodie dependency to fix automatic utf8 open.
View
1  MANIFEST
@@ -82,6 +82,7 @@ t/die.t
t/diff.t
t/dump/array.t
t/dump/code.t
+t/dump/formats.t
t/dump/hash.t
t/dump/obj.t
t/dump/scalar.t
View
15 META.json
@@ -55,6 +55,7 @@
"Digest::SHA" : "5.45",
"File::chdir" : "0.1002",
"Hash::Merge::Simple" : "0.04",
+ "Hash::StoredIterator" : "0.001",
"IPC::System::Simple" : "1.18",
"JSON" : "2.17",
"List::MoreUtils" : "0.22",
@@ -97,11 +98,11 @@
},
"perl5i" : {
"file" : "lib/perl5i.pm",
- "version" : "v2.10.0"
+ "version" : "v2.11.0"
},
"perl5i::0" : {
"file" : "lib/perl5i/0.pm",
- "version" : "v2.10.0"
+ "version" : "v2.11.0"
},
"perl5i::0::ARRAY" : {
"file" : "lib/perl5i/0/ARRAY.pm",
@@ -137,7 +138,7 @@
},
"perl5i::1" : {
"file" : "lib/perl5i/1.pm",
- "version" : "v2.10.0"
+ "version" : "v2.11.0"
},
"perl5i::1::ARRAY" : {
"file" : "lib/perl5i/1/ARRAY.pm",
@@ -181,7 +182,7 @@
},
"perl5i::2" : {
"file" : "lib/perl5i/2.pm",
- "version" : "v2.10.0"
+ "version" : "v2.11.0"
},
"perl5i::2::ARRAY" : {
"file" : "lib/perl5i/2/ARRAY.pm",
@@ -269,7 +270,7 @@
},
"perl5i::VERSION" : {
"file" : "lib/perl5i/VERSION.pm",
- "version" : "v2.10.0"
+ "version" : "v2.11.0"
},
"perl5i::cmd" : {
"file" : "lib/perl5i/cmd.pm",
@@ -277,7 +278,7 @@
},
"perl5i::latest" : {
"file" : "lib/perl5i/latest.pm",
- "version" : "v2.10.0"
+ "version" : "v2.11.0"
}
},
"release_status" : "stable",
@@ -292,5 +293,5 @@
"url" : "http://github.com/schwern/perl5i/tree/master"
}
},
- "version" : "v2.10.0"
+ "version" : "v2.11.0"
}
View
15 META.yml
@@ -40,10 +40,10 @@ provides:
version: 0
perl5i:
file: lib/perl5i.pm
- version: v2.10.0
+ version: v2.11.0
perl5i::0:
file: lib/perl5i/0.pm
- version: v2.10.0
+ version: v2.11.0
perl5i::0::ARRAY:
file: lib/perl5i/0/ARRAY.pm
version: 0
@@ -70,7 +70,7 @@ provides:
version: 0
perl5i::1:
file: lib/perl5i/1.pm
- version: v2.10.0
+ version: v2.11.0
perl5i::1::ARRAY:
file: lib/perl5i/1/ARRAY.pm
version: 0
@@ -103,7 +103,7 @@ provides:
version: 0
perl5i::2:
file: lib/perl5i/2.pm
- version: v2.10.0
+ version: v2.11.0
perl5i::2::ARRAY:
file: lib/perl5i/2/ARRAY.pm
version: 0
@@ -169,13 +169,13 @@ provides:
version: 0
perl5i::VERSION:
file: lib/perl5i/VERSION.pm
- version: v2.10.0
+ version: v2.11.0
perl5i::cmd:
file: lib/perl5i/cmd.pm
version: 0
perl5i::latest:
file: lib/perl5i/latest.pm
- version: v2.10.0
+ version: v2.11.0
requires:
CLASS: 1.00
Capture::Tiny: 0.06
@@ -189,6 +189,7 @@ requires:
Digest::SHA: 5.45
File::chdir: 0.1002
Hash::Merge::Simple: 0.04
+ Hash::StoredIterator: 0.001
IPC::System::Simple: 1.18
JSON: 2.17
List::MoreUtils: 0.22
@@ -217,4 +218,4 @@ resources:
bugtracker: http://github.com/schwern/perl5i/issues
license: http://dev.perl.org/licenses/
repository: http://github.com/schwern/perl5i/tree/master
-version: v2.10.0
+version: v2.11.0
View
304 README
@@ -24,24 +24,24 @@ DESCRIPTION
Using perl5i
Because perl5i *plans* to be incompatible in the future, you do not
- simply `use perl5i'. You must declare which major version of perl5i you
+ simply "use perl5i". You must declare which major version of perl5i you
are using. You do this like so:
# Use perl5i major version 2
use perl5i::2;
- Thus the code you write with, for example, `perl5i::2' will always
+ Thus the code you write with, for example, "perl5i::2" will always
remain compatible even as perl5i moves on.
- If you want to be daring, you can `use perl5i::latest' to get the latest
- version. This will automatically happen if the program is `-e'. This
- lets you do slightly less typing for one-liners like `perl -Mperl5i -e
- ...'
+ If you want to be daring, you can "use perl5i::latest" to get the latest
+ version. This will automatically happen if the program is "-e". This
+ lets you do slightly less typing for one-liners like "perl -Mperl5i -e
+ ..."
If you want your module to depend on perl5i, you should depend on the
- versioned class. For example, depend on `perl5i::2' and not `perl5i'.
+ versioned class. For example, depend on "perl5i::2" and not "perl5i".
- See VERSIONING for more information about perl5i's versioning scheme.
+ See "VERSIONING" for more information about perl5i's versioning scheme.
What it does
perl5i enables each of these modules and adds/changes these functions.
@@ -65,7 +65,7 @@ What it does
# the reference type of the object
my $reftype = $obj->mo->reftype;
- A meta object is used to avoid polluting the global method space. `mo'
+ A meta object is used to avoid polluting the global method space. "mo"
was chosen to avoid clashing with Moose's meta object.
See perl5i::Meta for complete details.
@@ -85,7 +85,7 @@ What it does
return bless \%args, $class;
}
- `func' and `method' define subroutines as `sub' does, with some extra
+ "func" and "method" define subroutines as "sub" does, with some extra
conveniences.
The signature syntax is currently very simple. The content will be
@@ -102,8 +102,8 @@ What it does
return $this + $that;
}
- `method' defines a method. This is the same as a subroutine, but the
- first argument, the *invocant*, will be removed and made into `$self'.
+ "method" defines a method. This is the same as a subroutine, but the
+ first argument, the *invocant*, will be removed and made into $self.
method get($key) {
return $self->{$key};
@@ -116,10 +116,10 @@ What it does
}
Methods have a special bit of syntax. If the first item in the siganture
- is `$var:' it will change the variable used to store the invocant.
+ is $var: it will change the variable used to store the invocant.
method new($class: %args) {
- return bless $class, \%args;
+ return bless \%args, $class;
}
is equivalent to:
@@ -127,7 +127,7 @@ What it does
sub new {
my $class = shift;
my %args = @_;
- return bless $class, \%args;
+ return bless \%args, $class;
}
Anonymous functions and methods work, too.
@@ -152,7 +152,7 @@ What it does
Parameter traits
Traditional prototypes
- See http://github.com/schwern/perl5i/issues/labels/syntax#issue/19 for
+ See <http://github.com/schwern/perl5i/issues/labels/syntax#issue/19> for
more details about future expansions.
The equivalencies above should only be taken for illustrative purposes,
@@ -169,16 +169,16 @@ What it does
The extra argument is ignored. In future versions of perl5i this will be
a runtime error.
- Signature Introspection
- The signature of a subroutine defined with `func' or `method' can be
- queried by calling the `signature' method on the code reference.
+ Signature Introspection
+ The signature of a subroutine defined with "func" or "method" can be
+ queried by calling the "signature" method on the code reference.
func hello($greeting, $place) { say "$greeting, $place" }
my $code = \&hello;
say $code->signature->num_positional_params; # prints 2
- Functions defined with `sub' will not have a signature.
+ Functions defined with "sub" will not have a signature.
See perl5i::Signature for more details.
@@ -189,9 +189,9 @@ What it does
polluting the global namespace.
autobox::Core wraps a lot of Perl's built in functions so they can be
- called as methods on unblessed variables. `@a->pop' for example.
+ called as methods on unblessed variables. "@a->pop" for example.
- alias
+ alias
$scalar_reference->alias( @identifiers );
@alias->alias( @identifiers );
%hash->alias( @identifiers );
@@ -225,8 +225,8 @@ What it does
say Some::Class->foo; # prints 99
If there is just one @identifier and it has no "::" in it, the current
- caller will be prepended. `$thing->alias("name")' is shorthand for
- `$thing->alias(CLASS, "name")'
+ caller will be prepended. "$thing->alias("name")" is shorthand for
+ "$thing->alias(CLASS, "name")"
Due to limitations in autobox, non-reference scalars cannot be aliased.
Alias a scalar ref instead.
@@ -247,30 +247,30 @@ What it does
in addition, perl5i adds some methods of its own.
- center
+ center
my $centered_string = $string->center($length);
my $centered_string = $string->center($length, $character);
Centers $string between $character. $centered_string will be of length
$length.
- `$character' defaults to " ".
+ $character defaults to " ".
say "Hello"->center(10); # " Hello ";
say "Hello"->center(10, '-'); # "---Hello--";
- `center()' will never truncate `$string'. If $length is less than
- `$string->length' it will just return `$string'.
+ "center()" will never truncate $string. If $length is less than
+ "$string->length" it will just return $string.
say "Hello"->center(4); # "Hello";
- round
+ round
my $rounded_number = $number->round;
Round to the nearest integer.
- round_up
- ceil
+ round_up
+ ceil
my $new_number = $number->round_up;
Rounds the $number towards infinity.
@@ -280,8 +280,8 @@ What it does
ceil() is a synonym for round_up().
- round_down
- floor
+ round_down
+ floor
my $new_number = $number->round_down;
Rounds the $number towards negative infinity.
@@ -291,7 +291,7 @@ What it does
floor() is a synonyn for round_down().
- is_number
+ is_number
$is_a_number = $thing->is_number;
Returns true if $thing is a number understood by Perl.
@@ -300,31 +300,31 @@ What it does
"12.34"->is_number; # also true
"eleven"->is_number; # false
- is_positive
+ is_positive
$is_positive = $thing->is_positive;
Returns true if $thing is a positive number.
0 is not positive.
- is_negative
+ is_negative
$is_negative = $thing->is_negative;
Returns true if $thing is a negative number.
0 is not negative.
- is_even
+ is_even
$is_even = $thing->is_even;
Returns true if $thing is an even integer.
- is_odd
+ is_odd
$is_odd = $thing->is_odd;
Returns true if $thing is an odd integer.
- is_integer
+ is_integer
$is_an_integer = $thing->is_integer;
Returns true if $thing is an integer.
@@ -333,10 +333,10 @@ What it does
12.34->is_integer; # false
"eleven"->is_integer; # false
- is_int
+ is_int
A synonym for is_integer
- is_decimal
+ is_decimal
$is_a_decimal_number = $thing->is_decimal;
Returns true if $thing is a decimal number.
@@ -346,15 +346,15 @@ What it does
".34"->is_decimal; # true
"point five"->is_decimal; # false
- require
+ require
my $module = $module->require;
- Will `require' the given $module. This avoids funny things like `eval
- qq[require $module] or die $@'. It accepts only module names.
+ Will "require" the given $module. This avoids funny things like "eval
+ qq[require $module] or die $@". It accepts only module names.
- On failure it will throw an exception, just like `require'. On a success
+ On failure it will throw an exception, just like "require". On a success
it returns the $module. This is mostly useful so that you can
- immediately call $module's `import' method to emulate a `use'.
+ immediately call $module's "import" method to emulate a "use".
# like "use $module qw(foo bar);" if that worked
$module->require->import(qw(foo bar));
@@ -362,7 +362,7 @@ What it does
# like "use $module;" if that worked
$module->require->import;
- wrap
+ wrap
my $wrapped = $string->wrap( width => $cols, separator => $sep );
Wraps $string to width $cols, breaking lines at word boundries using
@@ -373,9 +373,9 @@ What it does
See Text::Wrap for details.
- ltrim
- rtrim
- trim
+ ltrim
+ rtrim
+ trim
my $trimmed = $string->trim;
my $trimmed = $string->trim($character_set);
@@ -388,16 +388,16 @@ What it does
They all take an optional $character_set which will determine what
characters should be trimmed. It follows regex character set syntax so
- `A-Z' will trim everything from A to Z. Defaults to `\s', whitespace.
+ "A-Z" will trim everything from A to Z. Defaults to "\s", whitespace.
- my $string = '-> test <-'->trim('-><'); # ' test '
+ my $string = '-> test <-'->trim('-><'); # ' test '
- title_case
+ title_case
my $name = 'joe smith'->title_case; # Joe Smith
Will uppercase every word character that follows a wordbreak character.
- path2module
+ path2module
my $module = $path->path2module;
Given a relative $path it will return the Perl module this represents.
@@ -408,7 +408,7 @@ What it does
It will throw an exception if given something which could not be a path
to a Perl module.
- module2path
+ module2path
my $path = $module->module2path;
Will return the relative $path in which the Perl $module can be found.
@@ -416,7 +416,7 @@ What it does
"Foo::Bar"->module2path; # "Foo/Bar.pm"
- is_module_name
+ is_module_name
my $is_valid = $string->is_module_name;
Will return true if the $string is a valid module name.
@@ -424,7 +424,7 @@ What it does
"Foo::Bar"->is_module_name; # true
"Foo/Bar"->is_module_name; # false
- group_digits
+ group_digits
my $number_grouped = $number->group_digits;
my $number_grouped = $number->group_digits(\%options);
@@ -432,7 +432,7 @@ What it does
grouping".
It honors your current locale to determine the separator and grouping.
- This can be overridden using `%options'.
+ This can be overridden using %options.
NOTE: many systems do not have their numeric locales set properly
@@ -459,7 +459,7 @@ What it does
1234->group_digits; # 1,234 (assuming US locale)
1234->group_digits( separator => "." ); # 1.234
- commify
+ commify
my $number_grouped = $number->commify;
my $number_grouped = $number->commify(\%options);
@@ -467,13 +467,13 @@ What it does
useful when you want a predictable result regardless of the user's
locale settings.
- `%options' defaults to `( separator => ",", grouping => 3, decimal_point
- => "." )'. Each key will be overridden individually.
+ %options defaults to "( separator => ",", grouping => 3, decimal_point
+ => "." )". Each key will be overridden individually.
1234->commify; # 1,234
1234->commify({ separator => "." }); # 1.234
- reverse
+ reverse
my $reverse = $string->reverse;
Reverses a $string.
@@ -482,7 +482,8 @@ What it does
context.
Array Autoboxing
- The methods provided by autobox::Core are available from perl5i.
+ The methods provided by "Array Methods" in autobox::Core are available
+ from perl5i.
All the functions from List::Util and select ones from List::MoreUtils
are all available as methods on unblessed arrays and array refs: first,
@@ -494,10 +495,10 @@ What it does
@array->grep(sub{ $_->is_number })->sum->say;
- foreach
+ foreach
@array->foreach( func($item) { ... } );
- Works like the built in `foreach', calls the code block for each element
+ Works like the built in "foreach", calls the code block for each element
of @array passing it into the block.
@array->foreach( func($item) { say $item } ); # print each item
@@ -515,7 +516,7 @@ What it does
If @array is not a multiple of the iteration (for example, @array has 5
elements and you ask 2 at a time) the behavior is currently undefined.
- as_hash
+ as_hash
my %hash = @array->as_hash;
This method returns a %hash where each element of @array is a key. The
@@ -529,7 +530,7 @@ What it does
my %hash = @array->as_hash;
say q[@array contains 'a'] if $hash{"a"};
- pick
+ pick
my @rand = @array->pick($number);
The pick() method returns a list of $number elements in @array. If
@@ -541,7 +542,7 @@ What it does
my @array = (1, 2, 3, 4);
my @rand = @array->pick(2);
- pick_one
+ pick_one
my $rand = @array->pick_one;
The pick_one() method returns a random element in @array. It is similar
@@ -552,7 +553,7 @@ What it does
my @array = (1,2,3,4);
my $rand = @array->pick_one;
- diff
+ diff
Calculate the difference between two (or more) arrays:
my @a = ( 1, 2, 3 );
@@ -561,9 +562,9 @@ What it does
my @diff_a = @a->diff(\@b) # [ 1, 2 ]
my @diff_b = @b->diff(\@a) # [ 4, 5 ]
- Diff returns all elements in array `@a' that are not present in array
- `@b'. Item order is not considered: two identical elements in both
- arrays will be recognized as such disregarding their index.
+ Diff returns all elements in array @a that are not present in array @b.
+ Item order is not considered: two identical elements in both arrays will
+ be recognized as such disregarding their index.
[ qw( foo bar ) ]->diff( [ qw( bar foo ) ] ) # empty, they are equal
@@ -571,8 +572,8 @@ What it does
@a->diff(\@b, \@c, ... )
- All comparisons are against the base array (`@a' in this example). The
- result will be composed of all those elements that were present in `@a'
+ All comparisons are against the base array (@a in this example). The
+ result will be composed of all those elements that were present in @a
and in none other.
It also works with nested data structures; it will traverse them
@@ -589,20 +590,20 @@ What it does
[ $uri ]->diff( [ "http://www.perl.com" ] ); # empty, they are equal
[ $uri ]->diff( [ $uri2 ] ); # empty, they are equal
- popn
+ popn
my @newarray = @array->popn($n);
- Pops `$n' values from the `@array'.
+ Pops $n values from the @array.
- If `$n' is greater than the length of `@array', it will return the whole
- `@array'. If `$n' is 0, it will return an empty array.
+ If $n is greater than the length of @array, it will return the whole
+ @array. If $n is 0, it will return an empty array.
- A negative `$n' or non-integer is an error.
+ A negative $n or non-integer is an error.
my @array = (1, 2, 3, 4, 5);
my @newarray = @array->popn(3); # (3, 4, 5)
- shiftn
+ shiftn
my @newarray = @array->shiftn($n);
Works like popn, but it shifts off the front of the array instead of
@@ -611,7 +612,7 @@ What it does
my @array = (1, 2, 3, 4, 5);
my @newarray = @array->shiftn(3); # (1, 2, 3)
- intersect
+ intersect
my @a = (1 .. 10);
my @b = (5 .. 15);
@@ -620,13 +621,13 @@ What it does
Performs intersection between arrays, returning those elements that are
present in all of the argument arrays simultaneously.
- As with `diff()', it works with any number of arrays, nested data
+ As with "diff()", it works with any number of arrays, nested data
structures of arbitrary depth, and handles overloaded objects
graciously.
- ltrim
- rtrim
- trim
+ ltrim
+ rtrim
+ trim
my @trimmed = @list->trim;
my @trimmed = @list->trim($character_set);
@@ -643,11 +644,12 @@ What it does
my @trimmed = ['-> foo <-', '-> bar <-']->trim('-><'); # [' foo ', ' bar ']
Hash Autoboxing
- All of the methods provided by autobox::Core are available from perl5i.
+ All of the methods provided by "Hash Methods" in autobox::Core are
+ available from perl5i.
In addition...
- each
+ each
Iterate through each key/value pair in a hash using a callback.
my %things = ( foo => 23, bar => 42 );
@@ -655,10 +657,10 @@ What it does
say "Key: $k, Value: $v"
});
- Unlike the `each' function, individual calls to each are guaranteed to
+ Unlike the "each" function, individual calls to each are guaranteed to
iterate through the entirety of the hash.
- flip
+ flip
Exchanges values for keys in a hash.
my %things = ( foo => 1, bar => 2, baz => 5 );
@@ -676,7 +678,7 @@ What it does
{ foo => [ 'bar', 'baz' ] }->flip; # dies
- merge
+ merge
Recursively merge two or more hashes together using Hash::Merge::Simple.
my $a = { a => 1 };
@@ -696,7 +698,7 @@ What it does
array references or objects. For more information, look at the
Hash::Merge::Simple docs.
- diff
+ diff
my %staff = ( bob => 42, martha => 35, timmy => 23 );
my %promoted = ( timmy => 23 );
@@ -704,35 +706,35 @@ What it does
Returns the key/value pairs present in the first hash that are not
present in the subsequent hash arguments. Otherwise works as
- `@array->diff'.
+ "@array->diff".
- intersect
+ intersect
%staff->intersect(\%promoted); # { timmy => 23 }
Returns the key/value pairs that are present simultaneously in all the
- hash arguments. Otherwise works as `@array->intersect'.
+ hash arguments. Otherwise works as "@array->intersect".
Code autoboxing
- signature
+ signature
my $sig = $code->signature;
- You can query the signature of any code reference defined with `func' or
- `method'. See Signature Introspection for details.
+ You can query the signature of any code reference defined with "func" or
+ "method". See "Signature Introspection" for details.
- If `$code' has a signature, returns an object representing `$code''s
+ If $code has a signature, returns an object representing $code's
signature. See perl5i::Signature for details. Otherwise it returns
nothing.
- caller
- Perl6::Caller causes `caller' to return an object in scalar context.
+ caller
+ Perl6::Caller causes "caller" to return an object in scalar context.
- die
- `die' now always returns an exit code of 255 instead of trying to use
- `$!' or `$?' which makes the exit code unpredictable. If you want to
- exit with a message and a special exit code, use `warn' then `exit'.
+ die
+ "die" now always returns an exit code of 255 instead of trying to use $!
+ or $? which makes the exit code unpredictable. If you want to exit with
+ a message and a special exit code, use "warn" then "exit".
- list
- `list' will force list context similar to how scalar will force scalar
+ list
+ "list" will force list context similar to how scalar will force scalar
context.
utf8::all
@@ -749,22 +751,22 @@ What it does
sub fünkßhüñ { ... }
Strings will be treated as a set of characters rather than a set of
- bytes. For example, `length' will return the number of characters, not
+ bytes. For example, "length" will return the number of characters, not
the number of bytes.
length("perl5i is MËTÁŁ"); # 15, not 18
- `@ARGV' will be read as UTF8.
+ @ARGV will be read as UTF8.
STDOUT, STDIN, STDERR and all newly opened filehandles will have UTF8
encoding turned on. Consequently, if you want to output raw bytes to a
- file, such as outputting an image, you must set `binmode $fh'.
+ file, such as outputting an image, you must set "binmode $fh".
- capture
+ capture
my($stdout, $stderr) = capture { ... } %options;
my $stdout = capture { ... } %options;
- `capture()' lets you capture all output to `STDOUT' and `STDERR' in any
+ "capture()" lets you capture all output to "STDOUT" and "STDERR" in any
block of code.
# $out = "Hello"
@@ -774,8 +776,8 @@ What it does
print STDERR "Bye";
};
- If called in scalar context, it will only return `STDOUT' and silence
- `STDERR'.
+ If called in scalar context, it will only return "STDOUT" and silence
+ "STDERR".
# $out = "Hello"
my $out = capture {
@@ -783,14 +785,14 @@ What it does
warn "oh god";
};
- `capture' takes some options.
+ "capture" takes some options.
tee tee will cause output to be captured yet still printed.
my $out = capture { print "Hi" } tee => 1;
merge
- merge will merge `STDOUT' and `STDERR' into one variable.
+ merge will merge "STDOUT" and "STDERR" into one variable.
# $out = "HiBye"
my $out = capture {
@@ -799,15 +801,15 @@ What it does
} merge => 1;
Carp
- `croak' and `carp' from Carp are always available.
+ "croak" and "carp" from Carp are always available.
The Carp message will always format consistently, smoothing over the
backwards incompatible change in Carp 1.25.
Child
- Child provides the `child' function which is a better way to do forking.
+ Child provides the "child" function which is a better way to do forking.
- `child' creates and starts a child process, and returns an
+ "child" creates and starts a child process, and returns an
Child::Link::Proc object which is a better interface for managing the
child process. The only required argument is a codeblock, which is
called in the new process. exit() is automatically called for you after
@@ -836,30 +838,30 @@ What it does
English
English gives English names to the punctuation variables; for instance,
- `<$@'> is also `<$EVAL_ERROR'>. See perlvar for details.
+ "<$@"> is also "<$EVAL_ERROR">. See perlvar for details.
It does not load the regex variables which affect performance.
- `$PREMATCH', `$MATCH', and `$POSTMATCH' will not exist. See the `p'
- modifier in perlre for a better alternative.
+ $PREMATCH, $MATCH, and $POSTMATCH will not exist. See the "p" modifier
+ in perlre for a better alternative.
Modern::Perl
Modern::Perl turns on strict and warnings, enables all the 5.10 features
- like `given/when', `say' and `state', and enables C3 method resolution
+ like "given/when", "say" and "state", and enables C3 method resolution
order.
CLASS
- Provides `CLASS' and `$CLASS' alternatives to `__PACKAGE__'.
+ Provides "CLASS" and $CLASS alternatives to "__PACKAGE__".
File::chdir
- File::chdir gives you `$CWD' representing the current working directory
- and it's assignable to `chdir'. You can also localize it to safely chdir
+ File::chdir gives you $CWD representing the current working directory
+ and it's assignable to "chdir". You can also localize it to safely chdir
inside a scope.
File::stat
- File::stat causes `stat' to return an object in scalar context.
+ File::stat causes "stat" to return an object in scalar context.
DateTime
- `time', `localtime', and `gmtime' are replaced with DateTime objects.
+ "time", "localtime", and "gmtime" are replaced with DateTime objects.
They will all act like the core functions.
# Sat Jan 10 13:37:04 2004
@@ -872,22 +874,22 @@ What it does
say time->year;
Time::y2038
- `gmtime()' and `localtime()' will now safely work with dates beyond the
+ "gmtime()" and "localtime()" will now safely work with dates beyond the
year 2038 and before 1901. The exact range is not defined, but we
guarantee at least up to 2**47 and back to year 1.
IO::Handle
Turns filehandles into objects so you can call methods on them. The
- biggest one is `autoflush' rather than mucking around with `$|' and
- `select'.
+ biggest one is "autoflush" rather than mucking around with $| and
+ "select".
$fh->autoflush(1);
autodie
- autodie causes system and file calls which can fail (`open', `system',
- and `chdir', for example) to die when they fail. This means you don't
- have to put `or die' at the end of every system call, but you do have to
- wrap it in an `eval' block if you want to trap the failure.
+ autodie causes system and file calls which can fail ("open", "system",
+ and "chdir", for example) to die when they fail. This means you don't
+ have to put "or die" at the end of every system call, but you do have to
+ wrap it in an "eval" block if you want to trap the failure.
autodie's default error messages are pretty smart.
@@ -899,27 +901,27 @@ What it does
$hash = {};
$hash->{key1}{key2};
- Results in `$hash->{key1}' coming into existence. That will no longer
+ Results in "$hash->{key1}" coming into existence. That will no longer
happen.
No indirect object syntax
- perl5i turns indirect object syntax, ie. `new $obj', into a compile time
+ perl5i turns indirect object syntax, ie. "new $obj", into a compile time
error. Indirect object syntax is largely unnecessary and removing it
avoids a number of ambiguous cases where Perl will mistakenly try to
turn a function call into an indirect method call.
See indirect for details.
- want()
- `want()' generalizes the mechanism of the wantarray function, allowing a
+ want
+ "want()" generalizes the mechanism of the wantarray function, allowing a
function to determine the context it's being called in. Want
distinguishes not just scalar v. array context, but void, lvalue,
rvalue, boolean, reference context, and more. See perldoc Want for full
details.
Try::Tiny
- Try::Tiny gives support for try/catch blocks as an alternative to `eval
- BLOCK'. This allows correct error handling with proper localization of
+ Try::Tiny gives support for try/catch blocks as an alternative to "eval
+ BLOCK". This allows correct error handling with proper localization of
$@ and a nice syntax layer:
# handle errors with a catch handler
@@ -957,14 +959,14 @@ Command line program
perl5i -e 'gmtime->year->say'
- And you can use it on the `#!' line.
+ And you can use it on the "#!" line.
#!/usr/bin/perl5i
gmtime->year->say;
- If you write a one-liner without using this program, saying `-Mperl5i'
- means `-Mperl5i::latest'. Please see "Using perl5i" and VERSIONING for
+ If you write a one-liner without using this program, saying "-Mperl5i"
+ means "-Mperl5i::latest". Please see "Using perl5i" and "VERSIONING" for
details.
BUGS
@@ -973,14 +975,14 @@ BUGS
If you're going to use two versions of perl5i together, we do not
currently recommend having them in the same package.
- See http://github.com/schwern/perl5i/issues/labels/bug for a complete
+ See <http://github.com/schwern/perl5i/issues/labels/bug> for a complete
list.
- Please report bugs at http://github.com/schwern/perl5i/issues/ or email
- mailto:perl5i@googlegroups.com.
+ Please report bugs at <http://github.com/schwern/perl5i/issues/> or
+ email <mailto:perl5i@googlegroups.com>.
VERSIONING
- perl5i follows the Semantic Versioning policy, http://semver.org. In
+ perl5i follows the Semantic Versioning policy, <http://semver.org>. In
short...
Versions will be of the form X.Y.Z.
@@ -1018,12 +1020,12 @@ LICENSE
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
- See http://dev.perl.org/licenses/artistic.html
+ See <http://dev.perl.org/licenses/artistic.html>
SEE ALSO
- Repository: http://github.com/schwern/perl5i/tree/master Issues/Bugs:
- http://github.com/schwern/perl5i/issues IRC: irc.perl.org on the #perl5i
- channel Mailing List: http://groups.google.com/group/perl5i/
+ Repository: <http://github.com/schwern/perl5i/tree/master> Issues/Bugs:
+ <http://github.com/schwern/perl5i/issues> IRC: irc.perl.org on the
+ #perl5i channel Mailing List: <http://groups.google.com/group/perl5i/>
Frequently Asked Questions about perl5i: perl5ifaq
View
11 lib/perl5i/2/HASH.pm
@@ -7,19 +7,12 @@ use warnings;
# Don't accidentally turn carp/croak into methods.
require Carp::Fix::1_25;
+require Hash::StoredIterator;
use perl5i::2::Signatures;
method each($callback) {
- # Reset the each() iterator
- keys %$self;
-
- my($k,$v);
- while( ($k,$v) = CORE::each(%$self) ) {
- $callback->($k,$v);
- }
-
- return;
+ return Hash::StoredIterator::eech( $callback, $self );
}
sub flip {
View
2  lib/perl5i/VERSION.pm
@@ -5,7 +5,7 @@ package perl5i::VERSION;
use strict;
use warnings;
-use version 0.77; our $VERSION = qv("v2.10.0");
+use version 0.77; our $VERSION = qv("v2.11.0");
sub latest { "perl5i::2" }; # LATEST HERE (for automated update)
View
72 t/each.t
@@ -45,4 +45,76 @@ note "each call is safe"; {
is_deeply \%have, \%want;
}
+note "Tests adapted from Hash::StoredIterator";
+
+my @want_outer = (
+ [a => 1],
+ [b => 2],
+ [c => 3],
+);
+
+my @want_inner = (
+ [a => 1],
+ [a => 1],
+ [a => 1],
+ [b => 2],
+ [b => 2],
+ [b => 2],
+ [c => 3],
+ [c => 3],
+ [c => 3],
+);
+
+my %hash = ( a => 1, b => 2, c => 3 );
+
+sub interference {
+ my @garbage = keys(%hash), values(%hash);
+ while ( my ( $k, $v ) = each(%hash) ) {
+ # Effectively do nothing
+ my $foo = $k . $v;
+ }
+};
+
+{
+ my @inner;
+ my @outer;
+
+ %hash->each( func( $k, $v ) {
+ ok( $k, "Got key" );
+ ok( $v, "Got val" );
+ is( $k, $_, '$_ is set to key' );
+ is( $k, $a, '$a is set to key' );
+ is( $v, $b, '$b is set to val' );
+
+ push @outer => [$k, $v];
+ interference();
+
+ %hash->each( func( $k2, $v2 ) {
+ is( $k2, $_, '$_ is set to key' );
+ is( $k2, $a, '$a is set to key' );
+ is( $v2, $b, '$b is set to val' );
+
+ push @inner => [$k, $v];
+
+ interference();
+ });
+
+ is( $k, $_, '$_ is not squashed by inner loop' );
+ is( $k, $a, '$a is not squashed by inner loop' );
+ is( $v, $b, '$a is not squashed by inner loop' );
+ });
+
+ is_deeply(
+ [sort { $a->[0] cmp $b->[0] } @outer],
+ \@want_outer,
+ "Outer loop got all keys"
+ );
+
+ is_deeply(
+ [sort { $a->[0] cmp $b->[0] } @inner],
+ \@want_inner,
+ "Inner loop got all keys multiple times"
+ );
+}
+
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.