Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into docs

Conflicts:
	lib/autobox/Core.pm
  • Loading branch information...
commit 77a0e7bcab359b94ad75e817b914504e62ea5365 2 parents 5cc7095 + 773e81a
Jacinta Richardson jarich authored
6 Makefile.PL
View
@@ -5,7 +5,11 @@ use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'autobox::Core',
VERSION_FROM => 'lib/autobox/Core.pm', # finds $VERSION
- PREREQ_PM => {autobox => 2.71},
+ PREREQ_PM => {
+ autobox => 2.71,
+ 'Test::More' => 0.88,
+
+ },
ABSTRACT_FROM => 'lib/autobox/Core.pm', # retrieve abstract from module
AUTHOR => 'Scott Walters scott@slowass.net',
(eval($ExtUtils::MakeMaker::VERSION) >= 6.31 ? (LICENSE => 'perl') : ()),
179 lib/autobox/Core.pm
View
@@ -213,49 +213,6 @@ L<vec|perlfunc/vec>, L<undef|perlfunc/undef>, L<m|perlfunc/m>,
L<nm|perlop/binding>,
L<s|perlfunc/s>, L<split|perlfunc/split>, L<system|perlfunc/system>, L<eval|perlfunc/eval>.
-=head4 cmp
-
- $cmp = $a->cmp($b);
-
- # or more likely:
-
- my @sorted = sort { $a->cmp($b) } @unsorted;
-
- # or
-
- my @sorted = @unsorted->sort( sub { $a->cmp($b) } );
-
-Compare two strings, just like the C<cmp> operator.
-
-If $a is greater, it returns 1. If $b is greater, it returns -1.
-If they're equal, it returns 0.
-
-=head4 eq
-
-C<eq> returns true if the values are equal strings.
-
- "foo"->eq("bar"); #false
- "foo"->eq("foo"); #true
-
- # or more likely:
-
- if( "foo"->eq("bar") ) {
-
- }
-
-=head4 ne
-
-=head4 ge
-
-=head4 gt
-
-=head4 le
-
-=head4 lt
-
-The string comparison operators of the same name. They're called like
-L<eq>.
-
=head4 concat
$string1->concat($string2);
@@ -443,38 +400,22 @@ Methods related to numbers.
The basic built in functions which operate as normal :
L<abs|perlfunc/abs>, L<atan2|perlfunc/atan2>, L<cos|perlfunc/cos>, L<exp|perlfunc/exp>,
L<int|perlfunc/int>, L<log|perlfunc/log>, L<oct|perlfunc/oct>, L<hex|perlfunc/hex>,
-L<rand|perlfunc/rand>, L<sin|perlfunc/sin>, and L<sqrt|perlfunc/sqrt>.
+L<sin|perlfunc/sin>, and L<sqrt|perlfunc/sqrt>.
Operators were given names as follows:
-=head4 add
-
-Corresponds to C<+>.
-
-=head4 and
-
- if( $a->and($b) ) {
- # $a and $b are true
- }
-
-Corresponds to C<&&> .
-
=head4 dec
$number->dec();
-
# $number is smaller by 1.
C<dec> corresponds to C<++>. Decrements subject, will decrement character
strings too: 'b' decrements to 'a'.
-=head4 div
-
- $number->div(3);
+=head4 flip
-C<div> returns the quotient of division (that is the non-fractional part).
-Same as C</>.
+C<flip> corresponds to C<~> which is the binary (rather than boolean) "not".
=head4 inc
@@ -485,44 +426,6 @@ strings too. 'a' increments to 'b'.
C<mod> corresponds to C<%>.
-=head4 mult
-
-C<mult> corresponds to C<*>.
-
-=head4 mcmp
-
-C<mcmp> compares two numbers and returns 0,1,-1 depending upon the type of input.
-
- 1->mcmp(5); # < 0
- 5->mcmp(5); # = 0
- 6->mcmp(5); # > 0
-
-"M" for "math".
-
-=head4 mge
-
-The C<< >= >> operator.
-
-=head4 meq
-
-The C<==> operator.
-
-=head4 mgt
-
-The C<< > >> operator.
-
-=head4 mle
-
-The C<< <= >> operator.
-
-=head4 mlt
-
-The C<< < >> operator.
-
-=head4 mne
-
-The C<!=> operator.
-
=head4 not
C<not> corresponds to C<!>.
@@ -543,10 +446,6 @@ C<pow> returns $number raised to the power of the $exponent.
C<rshift> corresponds to C<<< >> >>>.
-=head4 sub
-
-C<sub> corresponds to C<->.
-
=head4 xor
C<xor> corresponds to <^>.
@@ -874,7 +773,7 @@ Returns the @values of @keys.
=head4 put
- %hash->push(%other_hash);
+ %hash->put(%other_hash);
Overlays %other_hash on top of %hash.
@@ -993,19 +892,6 @@ the first argument filled in.
print $howdy_world->("Texas"); # "Howdy, Texas!"
-=head4 map
-
- my @mapped_array = $code->map(@array);
- my $mapped_array = $code->map(@array);
-
-Like L<map|perlfunc/map>. Runs each element of @array through $code
-and returns the transformed elements.
-
- sub { my $t = $_[0]; $t =~ tr/a-z/zyxwvutsrqponmlkjihgfedcba/; $t }->map(
- "Black", "crow", "flies", "at", "midnight"
- )->say;
-
-
=head2 What's Missing?
File and socket operations are already implemented in an object-oriented fashion
@@ -1373,8 +1259,6 @@ sub system { CORE::system @_; }
sub backtick { `$_[0]`; }
# Numeric functions
-# "abs", "atan2", "cos", "exp", "hex", "int", "log",
-# "oct", "rand", "sin", "sqrt", "srand"
sub abs { CORE::abs($_[0]) }
sub atan2 { CORE::atan2($_[0], $_[1]) }
@@ -1384,7 +1268,6 @@ sub int { CORE::int($_[0]) }
sub log { CORE::log($_[0]) }
sub oct { CORE::oct($_[0]) }
sub hex { CORE::hex($_[0]); }
-sub rand { CORE::rand($_[0]) }
sub sin { CORE::sin($_[0]) }
sub sqrt { CORE::sqrt($_[0]) }
@@ -1425,39 +1308,18 @@ sub strip {
}
# operator schizzle
-sub add { $_[0] + $_[1]; }
sub and { $_[0] && $_[1]; }
-sub band { $_[0] & $_[1]; }
-sub bor { $_[0] | $_[1]; }
-sub bxor { $_[0] ^ $_[1]; }
-sub cmp { $_[0] cmp $_[1]; }
sub dec { my $t = CORE::shift @_; --$t; }
-sub div { $_[0] / $_[1]; }
-sub eq { $_[0] eq $_[1]; }
sub flip { ~$_[0]; }
-sub ge { $_[0] ge $_[1]; }
-sub gt { $_[0] gt $_[1]; }
sub inc { my $t = CORE::shift @_; ++$t; }
-sub le { $_[0] le $_[1]; }
sub lshift { $_[0] << $_[1]; }
-sub lt { $_[0] lt $_[1]; }
sub mod { $_[0] % $_[1]; }
-sub mult { $_[0] * $_[1]; }
-sub mcmp { $_[0] <=> $_[1]; }
-sub ne { $_[0] ne $_[1]; }
sub neg { -$_[0]; }
-sub meq { $_[0] == $_[1]; }
-sub mge { $_[0] >= $_[1]; }
-sub mgt { $_[0] > $_[1]; }
-sub mle { $_[0] <= $_[1]; }
-sub mlt { $_[0] < $_[1]; }
-sub mne { $_[0] != $_[1]; }
sub not { !$_[0]; }
sub or { $_[0] || $_[1]; }
sub pow { $_[0] ** $_[1]; }
sub rpt { $_[0] x $_[1]; }
sub rshift { $_[0] >> $_[1]; }
-sub sub { $_[0] - $_[1]; }
sub xor { $_[0] ^ $_[1]; }
# sub bless (\%$) { CORE::bless $_[0], $_[1] } # HASH, ARRAY, CODE already have a bless() and blessing a non-reference works (autobox finds the reference in the pad or stash!). "can't bless a non-referenc value" for non-reference lexical and package scalars. this would work for (\$foo)->bless but then, unlike arrays, we couldn't find the reference to the variable again later so there's not much point I can see.
@@ -1554,7 +1416,6 @@ package autobox::Core::HASH;
use Carp 'croak';
# Functions for real %HASHes
-# "delete", "each", "exists", "keys", "values"
sub delete {
my $hash = CORE::shift;
@@ -1582,7 +1443,7 @@ sub values {
# local extensions
-sub get { my @res = $_[0]->{@_[1..$#_]}; return wantarray ? @res : \@res }
+sub get { @{$_[0]}{@_[1..$#_]}; }
*at = *get;
sub put {
@@ -1624,8 +1485,6 @@ sub each {
}
# Keywords related to classes and object-orientedness
-# "bless", "dbmclose", "dbmopen", "package", "ref",
-# "tie", "tied", "untie", "use"
sub bless { CORE::bless $_[0], $_[1] }
sub tie { CORE::tie $_[0], @_[1 .. $#_] }
@@ -1665,8 +1524,6 @@ use constant FIVETEN => ($] >= 5.010);
use Carp 'croak';
# Functions for list data
-# "grep", "join", "map", "qw/STRING/", "reverse",
-# "sort", "unpack"
# at one moment, perl5i had this in it:
@@ -1772,7 +1629,6 @@ sub min {
}
# Functions for real @ARRAYs
-# "pop", "push", "shift", "splice", "unshift"
sub pop { CORE::pop @{$_[0]}; }
@@ -2000,30 +1856,5 @@ sub ref { CORE::ref $_[0] }
sub curry { my $code = CORE::shift; my @args = @_; sub { CORE::unshift @_, @args; goto &$code; }; }
-# local - polymorphic
-
-sub map { my $code = CORE::shift; my @res = CORE::map { $code->($_) } @_; wantarray ? @res : \@res; }
-
1;
-__DATA__
-
-
- Regular expressions and pattern matching
- "m//", "pos", "quotemeta", "s///", "split", "study",
- "qr//"
-
-
- Functions for fixed length data or records
- "pack", "read", "syscall", "sysread", "syswrite",
- "unpack", "vec"
-
-
- Miscellaneous functions
- "defined", "dump", "eval", "formline", "local", "my",
- "our", "reset", "scalar", "undef", "wantarray"
-
- Keywords related to classes and object-orientedness
- "bless", "dbmclose", "dbmopen", "package", "ref",
- "tie", "tied", "untie", "use"
-
67 t/added.t
View
@@ -1,5 +1,4 @@
-use Test::More;
-BEGIN { plan tests => 73 };
+use Test::More 'no_plan';
use autobox::Core;
#####################################################################
@@ -10,61 +9,21 @@ ok(1);
#####################################################################
# Scalar
#####################################################################
-ok(1->add(5) == 6);
-
ok(1->and(5));
ok(!1->and(0));
-ok(1->band(5) == 1);
-
-ok(1->bor(5) == 5);
-
-ok(1->bxor(5) == 4);
-
-ok(1->cmp(5) == -1);
-
ok(1->dec == 0);
-ok(1->div(5) == 1/5);
-
-ok(not 1->eq(5));
-
ok(1->flip != 1);
-ok(not 1->ge(5));
-
-ok(not 1->gt(5));
-
ok(1->inc == 2);
-ok(1->le(5));
-
ok(1->lshift(5) == 32);
-ok(1->lt(5));
-
ok(5->mod(2) == 1);
-ok(1->mult(5) == 5);
-
-ok(1->mcmp(5) < 0);
-
-ok(1->ne(5));
-
ok(1->neg == -1);
-ok(not 1->meq(5));
-
-ok(not 1->mge(5));
-
-ok(not 1->mgt(5));
-
-ok(1->mle(5));
-
-ok(1->mlt(5));
-
-ok(1->mne(5));
-
ok(not 1->not);
ok(1->or(5));
@@ -75,8 +34,6 @@ ok(1->rpt(5) eq '11111');
ok(5->rshift(1) == 2);
-ok(1->sub(5) == -4);
-
ok(1->xor(5) == 4);
ok("1+5"->eval() == 6);
@@ -102,31 +59,25 @@ ok($a->[0] == 10 && $a->[@$a-1] == 1);
@a = 10->downto(1);
is_deeply \@a, [ reverse 1 .. 10 ];
-$a = 1;
-ok(10->times(sub {$a++}) == 10);
-ok($a == 11);
-
-$a = 1;
-$a++ for 10->times;
-ok($a == 11);
-
#####################################################################
# Hashes
#####################################################################
my $h = {a => 1, b => 2, c => 3};
-ok($h->at('b') == 2);
+is($h->at('b'), 2);
-ok($h->get('c') == 3);
+is($h->get('c'), 3);
$h->put('d' => 4, e=>5, f=>6);
-ok($h->get('e') == 5);
+is($h->get('e'), 5);
$h->put('g', 7);
-ok($h->get('g') == 7);
+is($h->get('g'), 7);
$h->set('h' => 8);
-ok($h->get('h') == 8);
+is($h->get('h'), 8);
$h->set('i', 9);
-ok($h->get('i') == 9);
+is($h->get('i'), 9);
+
+is_deeply [$h->get(qw(a b c))], [1, 2, 3];
is_deeply(
[ sort $h->flatten ],
17 t/map.t
View
@@ -1,4 +1,4 @@
-use Test::More qw(no_plan);
+use Test::More;
use strict;
use warnings;
@@ -17,17 +17,4 @@ use autobox::Core;
is ref $arrayref, 'ARRAY', "Returns arrayref in scalar context";
}
-{
- my @array = qw(1 2 3);
-
- my $add = sub { ++$_ };
-
- my @added = $add->map(@array);
-
- is_deeply \@added, [qw(2 3 4)];
-
- my $arrayref = $add->map(@added);
-
- is ref $arrayref, 'ARRAY', "Returns arrayref in scalar context";
-}
-
+done_testing;
1  t/numeric.t
View
@@ -17,5 +17,4 @@ cmp_ok( abs(05->hex - hex(05)), '<', $e );
cmp_ok( abs($num->sin - sin($num)), '<', $e );
cmp_ok( abs($num->sqrt - sqrt($num)), '<', $e );
-cmp_ok( $num->rand, '<=', $num );
cmp_ok( abs($num->atan2($num) - atan2($num, $num)), '<', $e );
Please sign in to comment.
Something went wrong with that request. Please try again.