Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

import autobox::Core 0.5 from CPAN

git-cpan-module: autobox::Core
git-cpan-version: 0.5
git-cpan-authorid: SWALTERS
  • Loading branch information...
commit 402a6ba51173eadbef2046f507b7f06d220fa072 1 parent ec71607
Scott Walters authored schwern committed
Showing with 41 additions and 20 deletions.
  1. +27 −11 Core.pm
  2. +7 −7 META.yml
  3. +7 −2 t/added.t
View
38 Core.pm
@@ -6,6 +6,7 @@ package autobox::Core;
# style dereferences. in perl, you could say $hashref->foo and $arrayref->5.
# okey, $arrayref->5 is invalid syntax. you'd have to say $five = 5; $arrayref->$five.
# hrm.
+# on second thought, I think that's a different module.
# XXX support 'my IO::Handle $io; $io->open('<', $fn);'. undef values belonging to
# SVs having associated types should dispatch to that class. of course, just using
@@ -18,13 +19,13 @@ use 5.8.0;
use strict;
use warnings;
-our $VERSION = '0.4';
+our $VERSION = '0.5';
=pod
=head1 NAME
-autobox::Core - Perl built-in functions exposed as methods in primitive types
+autobox::Core - Methods for core built-in functions in primitive types
=head1 SYNOPSIS
@@ -36,8 +37,8 @@ autobox::Core - Perl built-in functions exposed as methods in primitive types
=head1 DESCRIPTION
Methods wrapping F<perl>'s built-in functions for minipulating numbers, strings, arrays,
-hashes, and code references. It is handy to use built-in functions as methods to avoid
-messy dereferencing syntaxes and parenthesis pile ups.
+hashes, and code references. It can be handy to use built-in functions as methods to avoid
+messy dereferencing syntaxes and parentheses pile ups.
L<autobox> lets you call methods in scalars that aren't object references.
Numbers, strings, scalars containing numbers, scalars containing strings,
@@ -423,12 +424,17 @@ I<Here ends the text quoted from the Perl 6 Now manuscript.>
=head1 BUGS
-Yes. R eport them to the author, L<scott@slowass.net>.
+Yes. Report them to the author, L<scott@slowass.net>.
The API is not yet stable -- Perl 6-ish things and local extensions are still being renamed.
=head1 HISTORY
+Version 0.5 has an $arrayref->unshift bug fix and and a new flatten method for hashes.
+Also, this version is untested because my Hash::Util stopped working, dammit.
+
+Version 0.4 got numeric operations, if I remember.
+
Version 0.3 fixes a problem where C<unpack> wasn't sure it had enough arguments
according to a test introduced in Perl 5.8.6 or perhaps 5.8.5.
This problem was reported by Ron Reidy - thanks Ron!
@@ -441,25 +447,33 @@ Version 0.1 was woefully incomplete.
=head1 SEE ALSO
-L<autobox>.
+=over 1
+
+=item L<autobox>
-L<Perl6::Contexts>.
+=item L<Moose::Autobox>
-Perl 6: L<< http://dev.perl.org/perl6/apocalypse/ >>.
+=item L<Perl6::Contexts>
-(Shameless plug alert!) I<Perl 6 Now: The Core Ideas Illustrated with Perl 5>
+=item Perl 6: L<< http://dev.perl.org/perl6/apocalypse/ >>.
+
+=item (Shameless plug:) I<Perl 6 Now: The Core Ideas Illustrated with Perl 5>
dedicates a sizable portion of Chapter 14, Objects, to autoboxing
and the idea is used heavily throughout the book. Chapter 8, Data Structures,
also has numerous examples.
See L<http://perl6now.com> or look for ISBN 1-59059-395-2 at your favorite
bookstore for more information.
+=back
+
=head1 AUTHOR
Scott Walters, L<scott@slowass.net>.
Thanks to Matt Spear, who contributed tests and definitions for numeric operations.
-Thanks to chocolateboy for L<autobox> and for the encouragement!
+Ricardo SIGNES contributed patches.
+Mitchell N Charity reported a bug and sent a fix.
+Thanks to chocolateboy for L<autobox> and for the encouragement.
=cut
@@ -594,6 +608,8 @@ sub get(\%@) { $_[0]->{@_[1..$#_]}; }
sub put(\%%) { my $h = CORE::shift @_; my %h = @_; while(my ($k, $v) = CORE::each %h) { $h->{$k} = $v; }; $h; }
sub set(\%%) { my $h = CORE::shift @_; my %h = @_; while(my ($k, $v) = CORE::each %h) { $h->{$k} = $v; }; $h; }
+sub flatten(\%) { %{$_[0]} }
+
# local
sub each (\%$) {
@@ -670,7 +686,7 @@ sub min(\@) { my $arr = CORE::shift; my $min = $arr->[0]; foreach (@$arr) {$min
sub pop (\@) { CORE::pop @{$_[0]}; }
sub push (\@;@) { my $arr = CORE::shift; CORE::push @$arr, @_; $arr; }
-sub unshift (\@;@) { CORE::unshift @{$_[0]}, @_; $_[0]; }
+sub unshift (\@;@) { my $a = CORE::shift; CORE::unshift(@$a, @_); $a; }
sub delete (\@$) { my $arr = CORE::shift; CORE::delete $arr->[$_[0]] }
sub vdelete(\@$) { my $arr = CORE::shift; @$arr = CORE::grep {$_ ne $_[0]} @$arr; }
sub shift (\@;@) { my $arr = CORE::shift; CORE::shift @$arr; } # last to prevent having to prefix normal shift calls with CORE::
View
14 META.yml
@@ -1,14 +1,14 @@
--- #YAML:1.0
name: autobox-Core
-version: 0.4
-abstract: Perl built-in functions exposed as methods in primitive types
+version: 0.5
+abstract: Methods for core built-in functions in primitive types
license: ~
-generated_by: ExtUtils::MakeMaker version 6.32
+author:
+ - Scott Walters scott@slowass.net
+generated_by: ExtUtils::MakeMaker version 6.44
distribution_type: module
requires:
autobox: 0.11
meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.2.html
- version: 1.2
-author:
- - Scott Walters scott@slowass.net
+ url: http://module-build.sourceforge.net/META-spec-v1.3.html
+ version: 1.3
View
9 t/added.t
@@ -1,5 +1,5 @@
-use Test;
-BEGIN { plan tests => 64 };
+use Test::More;
+BEGIN { plan tests => 65 };
use autobox;
use autobox::Core;
@@ -118,6 +118,11 @@ ok($h->get('h') == 8);
$h->set('i', 9);
ok($h->get('i') == 9);
+is_deeply(
+ [ sort $h->flatten ],
+ [ sort %$h ],
+ "flattening gets us all the contents",
+);
#####################################################################
# Array
Please sign in to comment.
Something went wrong with that request. Please try again.