Moose-Autobox-0.15/000755 000766 000766 00000000000 12233346513 013237 5ustar00rjbs000000 000000 Moose-Autobox-0.15/Changes000644 000766 000766 00000006274 12233346466 014552 0ustar00rjbs000000 000000 Revision history for Perl extension Moose::Autobox 0.15 Sun Oct 27 21:59:43 EDT 2013 - hide internal packages from PAUSE - point repo/bugtracker at GitHub 0.14 Sun Oct 27 21:59:43 EDT 2013 - typo fixes (dsteinbrunner) - repackage to drop MYMETA files - stop using 'use_ok' in tests 0.13 Wed Aug 29 09:56:58 EDT 2012 - switch from Perl6::Junction to Syntax::Keyword::Junction (rjbs) 0.12 Tue. Mar 20, 2012 - replace "use base" with "use parent" 0.11 Fri. Mar 23, 2010 - add each_n_values to Indexed (rafl and rjbs) - add first and last to Scalar and Array (t0m) 0.10 Mon. Oct 12 2009 - add each, each_key, each_value to Indexed (array and hash) (rjbs) - add split, words, lines to String (Sartak) - add 'to' to Number (Debolaz) 0.09 Thu. Oct 23, 2008 - update Perl6::Junction dependency and support new version 0.08 Mon. May 12, 2008 - add flatten method to Array and Hash - upped the dependency on autobox from 1.22 to 2.23 at the suggestion of chocolateboy - might as well up the Moose dependency too. 0.07 Mon. April 28, 2008 ~~ no more Module::Build, thanks mst ~~ * Moose::Autobox - added documentation about how to extend the autoboxed types (RT #34315) * Moose::Autobox::Hash Moose::Autobox::Indexed - added support for slice and hslice (jrockway) - added tests for this 0.06 Tues. Jan. 22, 2008 ~~ updated copyright dates & some docs ~~ * Moose::Autobox - fixed role application code to follow the new Moose::Util based API - upped the Moose version dependency - upped the autobox version dependency 0.05 Sun. Aug. 5, 2007 * Moose::Autobox - fixed loading approach so that Moose::Object doesn't end up in isa (thanks to mst) 0.04 Thurs. May 31, 2007 * Moose::Autobox::Hash - added method for shallow hash merging * Moose::Autobox::String - fixed rindex method * Moose::Autobox::Item - moved &dump from ::Ref to ::Item, so that it can be used for the other types too - added &perl method which is an alias for &dump for symmetry with Perl6's .perl * Moose::Autobox::Scalar/Array/Hash - added &print/&say to SCALAR, ARRAY and HASH 0.03 Thurs. Aug 17, 2006 * Moose::Autobox - we now inherit from autobox, now we don't have to do that ugly eval thing or manually load autobox when we want to use this module. - added &mixin_additional_role to allow mixing in of additional functionality (see examples/unit/*) * Moose::Autobox::Code - added the Y and U combinators + added new examples for units - ported from the Pugs examples/units directory 0.02 Sat. June 24, 2006 - fixed Moose::Autobox so that PAUSE won't try to index SCALAR, ARRAY, HASH and CODE. - added examples/ directory - ported tic-tac-toe from the Pugs examples * Moose::Autobox::Ref - added &dump method which will use Data::Dumper to return a dumped representation of the ref * Moose::Autobox::Array - added Junctions support with Perl6::Junction 0.01 Fri. June 9, 2006 - Autoboxing, all the cool kids are doing it ;) Moose-Autobox-0.15/examples/000755 000766 000766 00000000000 12233346513 015055 5ustar00rjbs000000 000000 Moose-Autobox-0.15/lib/000755 000766 000766 00000000000 12233346513 014005 5ustar00rjbs000000 000000 Moose-Autobox-0.15/Makefile.PL000644 000766 000766 00000001760 12233346430 015213 0ustar00rjbs000000 000000 use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Moose::Autobox', AUTHOR => 'Stevan Little ', VERSION_FROM => 'lib/Moose/Autobox.pm', ABSTRACT_FROM => 'lib/Moose/Autobox.pm', LICENSE => 'perl', PL_FILES => {}, PREREQ_PM => { 'autobox' => '2.23', 'parent' => 0, 'Moose' => '0.42', 'Syntax::Keyword::Junction' => 0, }, TEST_REQUIRES => { 'Test::More' => '0.89', 'Test::Exception' => '0.21', }, META_MERGE => { "meta-spec" => { version => 2 }, bugtracker => { web => "https://github.com/moose/Moose-Autobox/issues", }, resources => { repository => { type => 'git', url => 'https://github.com/moose/Moose-Autobox.git', web => 'https://github.com/moose/Moose-Autobox', }, }, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Moose-Autobox-*' }, ); Moose-Autobox-0.15/MANIFEST000644 000766 000766 00000001655 12233346513 014377 0ustar00rjbs000000 000000 Changes examples/tic_tac_toe.pl examples/units/bytes.pl examples/units/time.pl lib/Moose/Autobox.pm lib/Moose/Autobox/Array.pm lib/Moose/Autobox/Code.pm lib/Moose/Autobox/Defined.pm lib/Moose/Autobox/Hash.pm lib/Moose/Autobox/Indexed.pm lib/Moose/Autobox/Item.pm lib/Moose/Autobox/List.pm lib/Moose/Autobox/Number.pm lib/Moose/Autobox/Ref.pm lib/Moose/Autobox/Scalar.pm lib/Moose/Autobox/String.pm lib/Moose/Autobox/Undef.pm lib/Moose/Autobox/Value.pm Makefile.PL MANIFEST This list of files README t/000_load.t t/001_basic.t t/002_role_hierarchy.t t/003_p6_example.t t/004_list_compressions.t t/005_string.t t/006_y_combinator.t t/007_base.t t/008_flatten.t t/009_number.t t/010_each.t t/011_each_n_values.t t/012_first_last.t xt/release/pod.t xt/release/pod_coverage.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Moose-Autobox-0.15/META.json000644 000766 000766 00000002456 12233346513 014667 0ustar00rjbs000000 000000 { "abstract" : "Autoboxed wrappers for Native Perl datatypes ", "author" : [ "Stevan Little " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.8, CPAN::Meta::Converter version 2.132830", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Moose-Autobox", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Moose" : "0.42", "Syntax::Keyword::Junction" : "0", "autobox" : "2.23", "parent" : "0" } }, "test" : { "requires" : { "Test::Exception" : "0.21", "Test::More" : "0.89" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "https://github.com/moose/Moose-Autobox.git", "web" : "https://github.com/moose/Moose-Autobox" } }, "version" : "0.15", "x_bugtracker" : { "web" : "https://github.com/moose/Moose-Autobox/issues" } } Moose-Autobox-0.15/META.yml000644 000766 000766 00000001276 12233346513 014516 0ustar00rjbs000000 000000 --- abstract: 'Autoboxed wrappers for Native Perl datatypes ' author: - 'Stevan Little ' build_requires: ExtUtils::MakeMaker: 0 Test::Exception: 0.21 Test::More: 0.89 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.8, CPAN::Meta::Converter version 2.132830' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Moose-Autobox no_index: directory: - t - inc requires: Moose: 0.42 Syntax::Keyword::Junction: 0 autobox: 2.23 parent: 0 resources: repository: https://github.com/moose/Moose-Autobox.git version: 0.15 x_bugtracker: web: https://github.com/moose/Moose-Autobox/issues Moose-Autobox-0.15/README000644 000766 000766 00000001064 11264641513 014121 0ustar00rjbs000000 000000 Moose::Autobox version 0.08 =========================== See the individual module documentation for more information INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: autobox Moose Perl6::Junction COPYRIGHT AND LICENCE Copyright (C) 2006-2008 Infinity Interactive, Inc. http://www.iinteractive.com This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Moose-Autobox-0.15/t/000755 000766 000766 00000000000 12233346513 013502 5ustar00rjbs000000 000000 Moose-Autobox-0.15/xt/000755 000766 000766 00000000000 12233346513 013672 5ustar00rjbs000000 000000 Moose-Autobox-0.15/xt/release/000755 000766 000766 00000000000 12233346513 015312 5ustar00rjbs000000 000000 Moose-Autobox-0.15/xt/release/pod.t000644 000766 000766 00000000257 11264641513 016266 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Moose-Autobox-0.15/xt/release/pod_coverage.t000644 000766 000766 00000000316 11264641513 020135 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok();Moose-Autobox-0.15/t/000_load.t000644 000766 000766 00000001133 12233341576 015167 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 14; BEGIN { use_ok('Moose::Autobox'); use_ok('Moose::Autobox::Array'); use_ok('Moose::Autobox::Code'); use_ok('Moose::Autobox::Defined'); use_ok('Moose::Autobox::Hash'); use_ok('Moose::Autobox::Indexed'); use_ok('Moose::Autobox::Item'); use_ok('Moose::Autobox::List'); use_ok('Moose::Autobox::Number'); use_ok('Moose::Autobox::Ref'); use_ok('Moose::Autobox::Scalar'); use_ok('Moose::Autobox::String'); use_ok('Moose::Autobox::Undef'); use_ok('Moose::Autobox::Value'); }Moose-Autobox-0.15/t/001_basic.t000644 000766 000766 00000014641 12233341631 015332 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 69; use Moose::Autobox; my $VAR1; # for eval of dumps # SCALAR & UNDEF my $s; ok(!$s->defined, '... got a undefined value'); $s = 5; ok($s->defined, '... got a defined value'); eval $s->dump; is($VAR1, 5 , '... eval of SCALAR->dump works'); eval $s->flatten; is($VAR1, 5 , '... eval of SCALAR->flatten works'); eval $s->perl; is($s->perl, $s->dump, '... SCALAR->dump equals SCALAR->perl'); # CODE my $f1 = sub { @_ }; ok($f1->defined, '... created function'); my $f2 = eval { $f1->curry(1, 2, 3) }; ok($f2->defined, '... created curried function'); my $f3 = eval { $f1->rcurry(1, 2, 3) }; ok($f3->defined, '... created right-curried function'); is_deeply( [ $f2->(4, 5, 6) ], [ 1, 2, 3, 4, 5, 6 ], '... got the right return value from the curried function'); is_deeply( [ $f3->(4, 5, 6) ], [ 4, 5, 6, 1, 2, 3 ], '... got the right return value from the r-curried function'); ok((sub { 1 })->disjoin(sub { 0 })->(), '... disjoins properly'); ok((sub { 0 })->disjoin(sub { 1 })->(), '... disjoins properly'); ok(!(sub { 1 })->conjoin(sub { 0 })->(), '... conjoins properly'); ok(!(sub { 0 })->conjoin(sub { 1 })->(), '... conjoins properly'); my $compose = (sub { @_, 1 })->compose(sub { @_, 2 }); is_deeply( [ $compose->() ], [ 1, 2 ], '... got the right return value for compose'); # ARRAY my $a = [ 4, 2, 6, 78, 101, 2, 3 ]; is($a->length, 7, '... got the right length'); ok($a->defined, '... got the right defined value'); is_deeply( $a->map(sub { $_ + 2 }), [ map { $_ + 2 } (4, 2, 6, 78, 101, 2, 3) ], '... got the right return value for map'); is_deeply($a, [ 4, 2, 6, 78, 101, 2, 3 ], '... original value is unchanged'); my $b = [1, 2, 3]; $b->map(sub { $_++ } ); is_deeply($b, [ 2, 3, 4 ], '... original value is changed'); is_deeply( $a->reverse(), [ 3, 2, 101, 78, 6, 2, 4 ], '... got the right return value for reverse'); is_deeply($a, [ 4, 2, 6, 78, 101, 2, 3 ], '... original value is unchanged'); is_deeply( $a->grep(sub { $_ < 50 }), [ grep { $_ < 50 } (4, 2, 6, 78, 101, 2, 3) ], '... got the right return value grep'); is_deeply($a, [ 4, 2, 6, 78, 101, 2, 3 ], '... original value is unchanged'); is($a->join(', '), '4, 2, 6, 78, 101, 2, 3', '... got the right joined string'); is($a->join, '4267810123', '... got the right joined string'); ok($a->exists(0), '... exists works'); ok(!$a->exists(10), '... exists works'); is($a->pop(), 3, '... got the right pop-ed value'); is_deeply($a, [ 4, 2, 6, 78, 101, 2 ], '... original value is now changed'); is($a->shift(), 4, '... got the right unshift-ed value'); is_deeply($a, [ 2, 6, 78, 101, 2 ], '... original value is now changed'); is_deeply( $a->slice([ 1, 2, 4 ]), [ 6, 78, 2 ], '... got the right sliced value'); is_deeply( $a->unshift(10), [ 10, 2, 6, 78, 101, 2 ], '... got the correct unshifted value'); is_deeply( $a->unshift(15, 20, 30), [ 15, 20, 30, 10, 2, 6, 78, 101, 2 ], '... got the correct unshifted value (multiple values)'); is_deeply( $a->push(10), [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10 ], '... got the correct pushed value'); is_deeply( $a->push(15, 20, 30), [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], '... got the correct pushed value (multiple values)'); is_deeply( $a->sort(sub { $_[0] <=> $_[1] }), [ 2, 2, 6, 10, 10, 15, 15, 20, 20, 30, 30, 78, 101 ], '... got the correct sorted value'); is_deeply( $a, [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], '... the original values are unchanged'); is_deeply( []->push(10, 20, 30)->map(sub { ($_, $_ + 5) })->reverse, [ 35, 30, 25, 20, 15, 10 ], '... got the correct chained value'); is_deeply( $a->keys, [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], '... the keys'); is_deeply( $a->values, [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], '... the values'); is_deeply( $a->kv, [ [0, 15], [1, 20], [2, 30], [3, 10], [4, 2], [5, 6], [6, 78], [7, 101], [8, 2], [9, 10], [10, 15], [11, 20], [12, 30] ], '... [ k, v ]'); is([1, 2, 3, 4, 5]->reduce(sub { $_[0] + $_[1] }), 15, '... got the right reduction'); is_deeply( [1, 2, 3, 4, 5]->zip([ 5, 4, 3, 2, 1 ]), [ [1, 5], [2, 4], [3, 3], [4, 2], [5, 1] ], '... got the right zip'); is_deeply( [1, 2, 3, 4, 5]->zip([ 6, 5, 4, 3, 2, 1 ]), [ [1, 6], [2, 5], [3, 4], [4, 3], [5, 2], [undef, 1] ], '... got the right zip'); is($a->delete(2), 30, '... got the value deleted'); is_deeply( $a, [ 15, 20, undef, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], '... the value is correctly deleted'); $a->put(2, 30); is_deeply( $a, [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], '... the value is correctly put'); eval($a->dump); is_deeply( $VAR1, [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], '... the value is correctly dumped'); is( $a->dump, $a->perl, '... the value is correctly dumped with perl()' ); is([1, 2, 3, 4, 5]->any, 3, '... any correctly found a value'); is([1, 1, 2, 3, 4, 5, 5]->one, 2, '... one correctly found one value'); is([1, 1, 2, 3, 4, 5, 5]->none , 6, '... none correctly did not find any of a value'); is([3, 3, 3]->all, 3, '... all correctly found all of a value'); # Hash my $h = { one => 1, two => 2, three => 3 }; ok($h->defined, '... got the right defined value'); is_deeply( $h->keys->sort, [ qw/one three two/ ], '... the keys'); is_deeply( $h->values->sort, [ 1, 2, 3 ], '... the values'); is_deeply( $h->kv->sort(sub { $_[0]->[1] <=> $_[1]->[1] }), [ ['one', 1], ['two', 2], ['three', 3] ], '... the kvs'); ok($h->exists('two'), '... exists works'); ok(!$h->exists('five'), '... !exists works'); $h->put('four' => 4); is_deeply( $h, { one => 1, two => 2, three => 3, four => 4 }, '... got the value added correctly'); is($h->at('four'), 4, '... got the value at "four"'); $h->delete('four'); is_deeply( $h, { one => 1, two => 2, three => 3 }, '... got the value deleted correctly'); is_deeply( $h->merge({ three => 33, four => 44 }), { one => 1, two => 2, three => 33, four => 44 }, '... got the hashes merged correctly'); eval($h->dump); is_deeply( $VAR1, { one => 1, two => 2, three => 3 }, '... the value is correctly dumped'); is( $h->dump, $h->perl, '... the value is correctly dumped with perl()' ); is_deeply( { one => 1, two => 2, three => 3 }->slice([qw/three one/]), [ qw/3 1/ ], '... hash slices ok' ); is_deeply( { one => 1, two => 2, three => 3 }->hslice([qw/two three/]), { two => 2, three => 3 }, '... hash hslices ok' ); Moose-Autobox-0.15/t/002_role_hierarchy.t000644 000766 000766 00000004606 12233341644 017255 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 21; use Moose::Autobox; ok(Moose::Autobox::SCALAR->does('Moose::Autobox::Scalar'), '... SCALAR does Moose::Autobox::Scalar'); ok(Moose::Autobox::SCALAR->does('Moose::Autobox::String'), '... SCALAR does Moose::Autobox::String'); ok(Moose::Autobox::SCALAR->does('Moose::Autobox::Number'), '... SCALAR does Moose::Autobox::Number'); ok(Moose::Autobox::SCALAR->does('Moose::Autobox::Value'), '... SCALAR does Moose::Autobox::Value'); ok(Moose::Autobox::SCALAR->does('Moose::Autobox::Defined'), '... SCALAR does Moose::Autobox::Defined'); ok(Moose::Autobox::SCALAR->does('Moose::Autobox::Item'), '... SCALAR does Moose::Autobox::Item'); ok(Moose::Autobox::ARRAY->does('Moose::Autobox::Array'), '... ARRAY does Moose::Autobox::Array'); ok(Moose::Autobox::ARRAY->does('Moose::Autobox::List'), '... ARRAY does Moose::Autobox::List'); ok(Moose::Autobox::ARRAY->does('Moose::Autobox::Indexed'), '... ARRAY does Moose::Autobox::Indexed'); ok(Moose::Autobox::ARRAY->does('Moose::Autobox::Ref'), '... ARRAY does Moose::Autobox::Ref'); ok(Moose::Autobox::ARRAY->does('Moose::Autobox::Defined'), '... ARRAY does Moose::Autobox::Defined'); ok(Moose::Autobox::ARRAY->does('Moose::Autobox::Item'), '... ARRAY does Moose::Autobox::Item'); ok(Moose::Autobox::HASH->does('Moose::Autobox::Hash'), '... HASH does Moose::Autobox::Hash'); ok(Moose::Autobox::HASH->does('Moose::Autobox::Indexed'), '... HASH does Moose::Autobox::Indexed'); ok(Moose::Autobox::HASH->does('Moose::Autobox::Ref'), '... HASH does Moose::Autobox::Ref'); ok(Moose::Autobox::HASH->does('Moose::Autobox::Defined'), '... HASH does Moose::Autobox::Defined'); ok(Moose::Autobox::HASH->does('Moose::Autobox::Item'), '... HASH does Moose::Autobox::Item'); ok(Moose::Autobox::CODE->does('Moose::Autobox::Code'), '... CODE does Moose::Autobox::Code'); ok(Moose::Autobox::CODE->does('Moose::Autobox::Ref'), '... CODE does Moose::Autobox::Ref'); ok(Moose::Autobox::CODE->does('Moose::Autobox::Defined'), '... CODE does Moose::Autobox::Defined'); ok(Moose::Autobox::CODE->does('Moose::Autobox::Item'), '... CODE does Moose::Autobox::Item'); Moose-Autobox-0.15/t/003_p6_example.t000644 000766 000766 00000002462 12233341512 016307 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 7; use Test::Exception; require Moose::Autobox; =pod This comes from one of the examples in the Pugs distro. =cut { package Units::Bytes; use Moose::Role; use Moose::Autobox; sub bytes { $_[0] } sub kilobytes { $_[0] * 1024 } sub megabytes { $_[0] * 1024->kilobytes } sub gigabytes { $_[0] * 1024->megabytes } sub terabytes { $_[0] * 1024->gigabytes } { no warnings 'once'; # << squelch the stupid "used only once, maybe typo" warnings *byte = \&bytes; *kilobyte = \&kilobytes; *megabyte = \&megabytes; *gigabyte = \&gigabytes; *terabyte = \&terabytes; } } Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Bytes'); sub testing_bytes { ::dies_ok { 10->bytes } '... cannot do the autoboxing lexically'; } { use Moose::Autobox; is(5->bytes, 5, '... got 5 bytes'); is(5->kilobytes, 5120, '... got 5 kilobytes'); is(2->megabytes, 2097152, '... got 2 megabytes'); is(1->gigabyte, 1073741824, '... got 1 gigabyte'); is(2->terabytes, 2199023255552, '... got 2 terabyte'); testing_bytes; } dies_ok { 5->bytes } '... no longer got 5 bytes'; Moose-Autobox-0.15/t/004_list_compressions.t000644 000766 000766 00000001322 12233341660 020025 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 4; use Moose::Autobox; is_deeply( [ 1 .. 5 ]->map(sub { $_ * $_ }), [ 1, 4, 9, 16, 25 ], '... got the expected return values'); is_deeply( [ 1 .. 5 ]->map(sub { $_ * $_ })->do(sub { $_->zip($_) }), [ [1, 1], [4, 4], [9, 9], [16, 16], [25, 25] ], '... got the expected return values'); is( # sprintf an array ... [ 1 .. 5 ]->sprintf("%d -> %d -> %d"), '1 -> 2 -> 3', '... got the sprintf-ed values'); is( # sprintf an array ... [ 1 .. 5 ]->do(sub { $_->sprintf( $_->keys ->map(sub { '%d (' . $_ . ')' }) ->join(' -> ')) }), '1 (0) -> 2 (1) -> 3 (2) -> 4 (3) -> 5 (4)', '... got a more elaboratly sprintf-ed values'); Moose-Autobox-0.15/t/005_string.t000644 000766 000766 00000003451 12233341674 015567 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 22; use Test::Exception; use Moose::Autobox; my $VAR1; # for eval of dumps is('Hello World'->lc, 'hello world', '... $str->lc'); is('Hello World'->uc, 'HELLO WORLD', '... $str->uc'); is('foo'->ucfirst, 'Foo', '... $str->ucfirst'); is('Foo'->lcfirst, 'foo', '... $str->lcfirst'); dies_ok { ('Hello')->chop } '... cannot modify a read-only'; { my $greeting = 'Hello'; is($greeting->chop, 'o', '... got the chopped off portion of the string'); is($greeting, 'Hell', '... and are left with the rest of the string'); } dies_ok { "Hello\n"->chomp } '... cannot modify a read-only'; { my $greeting = "Hello\n"; is($greeting->chomp, '1', '... got the chopped off portion of the string'); is($greeting, 'Hello', '... and are left with the rest of the string'); } is('reverse'->reverse, 'esrever', '... got the string reversal'); is('length'->length, 6, '... got the string length'); is('Hello World'->index('World'), 6, '... got the correct index'); is('Hello World, Hello'->index('Hello'), 0, '... got the correct index'); is('Hello World, Hello'->index('Hello', 6), 13, '... got the correct index'); is('Hello World, Hello'->rindex('Hello'), 13, '... got the correct right index'); is('Hello World, Hello'->rindex('Hello', 6), 0, '... got the correct right index'); is_deeply('/foo/bar/baz'->split('/'), ['', 'foo', 'bar', 'baz'], '... got the correct fragments'); is_deeply('Hello World'->words, ['Hello', 'World'], '... got the correct words'); is_deeply("Hello\nWor\n\nld\n"->lines, ['Hello', 'Wor', '', 'ld'], '... got the correct lines'); eval 'Hello World, Hello'->dump; is($VAR1, 'Hello World, Hello' , '... eval of &dump works'); eval 'Hello World, Hello'->perl; is($VAR1, 'Hello World, Hello' , '... eval of &perl works'); Moose-Autobox-0.15/t/006_y_combinator.t000644 000766 000766 00000001202 12233341700 016725 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 2; use Test::Exception; use Moose::Autobox; # we need a control in the experiment sub fact { my $n = shift; return 1 if $n < 2; return $n * fact($n - 1); } *fact2 = sub { my $f = shift; sub { my $n = shift; return 1 if $n < 2; return $n * $f->($n - 1); } }->y; *fact3 = sub { my $f = shift; sub { my $n = shift; return 1 if $n < 2; return $n * ($f->($f))->($n - 1); } }->u; is(fact(10), fact2(10), '... our factorials match'); is(fact(10), fact3()->(10), '... our factorials match'); Moose-Autobox-0.15/t/007_base.t000644 000766 000766 00000000377 12233341711 015171 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 4; use Moose::Autobox (); foreach my $stem (qw(SCALAR ARRAY HASH CODE)) { my $class = "Moose::Autobox::${stem}"; ok(!$class->isa('Moose::Object'), "${class} !isa Moose::Object"); } Moose-Autobox-0.15/t/008_flatten.t000644 000766 000766 00000002677 11264641513 015730 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 9; use Moose::Autobox; my $array = [ qw(1 2 3 4 ) ]; is_deeply( [ $array->flatten ], [ 1, 2, 3, 4 ], "flattening an array returns a list", ); my $hash = { a => 1, b => 2 }; is_deeply( [ sort $hash->flatten ], [ qw(1 2 a b) ], "flattening a hash returns a list", ); my $scalar = 1; is_deeply( [ $scalar->flatten ], [ 1 ], "flattening a scalar returns the scalar", ); my $scalar_ref = \$scalar; is_deeply( [ $scalar_ref->flatten ], [ \$scalar ], "flattening a reference to a scalar returns the same scalar reference", ); # flatten_deep on array is_deeply( [ 1 .. 9 ]->flatten_deep, [ 1 .. 9 ], "default flatten_deep on shallow array returns correct array" ); is_deeply( [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ]->flatten_deep, [ 1 .. 9 ], "default flatten_deep on array with depth completely flattens array" ); is_deeply( [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ]->flatten_deep(undef), [ 1 .. 9 ], "flatten_deep with an undef argument on array with depth completely flattens array" ); is_deeply( [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ]->flatten_deep(0), [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ], "flatten_deep with depth 0 specified on array returns array unchanged" ); is_deeply( [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ]->flatten_deep(2), [ 1 .. 6, [ 7 .. 9 ] ], "flatten_deep with depth specified returns correct array" );Moose-Autobox-0.15/t/009_number.t000644 000766 000766 00000000405 12233341730 015542 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 3; use Moose::Autobox; is_deeply( 1->to(5), [ 1, 2, 3, 4, 5 ], '... got 1 to 5'); is_deeply( 5->to(1), [ 5, 4, 3, 2, 1 ], '... got 5 to 1'); is_deeply( 1->to(1), [ 1 ], '... got 1 to 1'); Moose-Autobox-0.15/t/010_each.t000644 000766 000766 00000002400 11264662405 015147 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 11; require_ok('Moose::Autobox'); use Moose::Autobox; { my %hash = ( a => 1, b => 2, c => 3, ); my $href = { %hash }; is_deeply($href, \%hash, "sanity check to start"); my @keys; $href->each_key(sub { push @keys, $_ }); is_deeply([ sort @keys ], [ sort keys %hash ], "keys found via each_key"); my @values; $href->each_value(sub { push @values, $_ }); is_deeply([ sort @values ], [ sort values %hash ], "values via each_values"); $href->each_value(sub { $_++ }); is($href->{a}, 2, "we can ++ values directly"); $href->each_key(sub { $_ = "$_$_" }); ok(! exists $href->{aa}, "we cannot alter keys directly"); } { my @array = qw(foo bar baz); my $aref = [ @array ]; is_deeply($aref, \@array, "sanity check to start"); my @keys; $aref->each_key(sub { push @keys, $_ }); is_deeply([ @keys ], [ 0, 1, 2 ], "keys found via each_key"); my @values; $aref->each_value(sub { push @values, $_ }); is_deeply([ @values ], [ @array ], "values via each_values"); $aref->each_value(sub { $_ = uc }); is($aref->[0], 'FOO', "we can alter values directly"); $aref->each_key(sub { $_ = $_ + 1 }); ok(! $aref->[3], "we cannot alter keys directly"); } Moose-Autobox-0.15/t/011_each_n_values.t000644 000766 000766 00000002136 11364402060 017040 0ustar00rjbs000000 000000 use strict; use warnings; use Test::More; use Moose::Autobox; { my @array = ('a' .. 'z'); my $aref = [ @array ]; { my @vals; @array->each_n_values(2, sub { push @vals, [@_] }); is(scalar @vals, 13); is(scalar @$_, 2) for @vals; is_deeply(@vals->map(sub { @{ $_ } }), [@array]); } { my @vals; $aref->each_n_values(2, sub { push @vals, [@_] }); is(scalar @vals, 13); is(scalar @$_, 2) for @vals; is_deeply(@vals->map(sub { @{ $_ } }), $aref); } } { my %hash = (a => 1, b => 2, c => 3, d => 4); my $href = { %hash }; { my @vals; %hash->each_n_values(2, sub { push @vals, [@_] }); my %seen; is(@vals, 2); for my $pair (@vals) { $seen{$_}++ for @$pair } is_deeply(\%seen, { 1,1,2,1,3,1,4,1 }); } { my @vals; $href->each_n_values(2, sub { push @vals, [@_] }); my %seen; is(@vals, 2); for my $pair (@vals) { $seen{$_}++ for @$pair } is_deeply(\%seen, { 1,1,2,1,3,1,4,1 }); } } done_testing; Moose-Autobox-0.15/t/012_first_last.t000644 000766 000766 00000000417 11364400500 016414 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 5; require_ok('Moose::Autobox'); use Moose::Autobox; my $string = 'foo'; my $list = ['foo', 'bar']; is $string->first, 'foo'; is $string->last, 'foo'; is $list->first, 'foo'; is $list->last, 'bar'; Moose-Autobox-0.15/lib/Moose/000755 000766 000766 00000000000 12233346513 015067 5ustar00rjbs000000 000000 Moose-Autobox-0.15/lib/Moose/Autobox/000755 000766 000766 00000000000 12233346513 016510 5ustar00rjbs000000 000000 Moose-Autobox-0.15/lib/Moose/Autobox.pm000644 000766 000766 00000010740 12233346437 017055 0ustar00rjbs000000 000000 package Moose::Autobox; use 5.006; use strict; use warnings; use Carp qw(confess); use Scalar::Util (); use Moose::Util (); our $VERSION = '0.15'; use parent 'autobox'; use Moose::Autobox::Undef; sub import { (shift)->SUPER::import( DEFAULT => 'Moose::Autobox::', UNDEF => 'Moose::Autobox::Undef', ); } sub mixin_additional_role { my ($class, $type, $role) = @_; ($type =~ /SCALAR|ARRAY|HASH|CODE/) || confess "Can only add additional roles to SCALAR, ARRAY, HASH or CODE"; Moose::Util::apply_all_roles(('Moose::Autobox::' . $type)->meta, ($role)); } { package Moose::Autobox::SCALAR; use Moose::Autobox::Scalar; use metaclass 'Moose::Meta::Class'; Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Scalar')); *does = \&Moose::Object::does; package Moose::Autobox::ARRAY; use Moose::Autobox::Array; use metaclass 'Moose::Meta::Class'; Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Array')); *does = \&Moose::Object::does; package Moose::Autobox::HASH; use Moose::Autobox::Hash; use metaclass 'Moose::Meta::Class'; Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Hash')); *does = \&Moose::Object::does; package Moose::Autobox::CODE; use Moose::Autobox::Code; use metaclass 'Moose::Meta::Class'; Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Code')); *does = \&Moose::Object::does; } 1; __END__ =pod =head1 NAME Moose::Autobox - Autoboxed wrappers for Native Perl datatypes =head1 SYNOPOSIS use Moose::Autobox; print 'Print squares from 1 to 10 : '; print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', '); =head1 DESCRIPTION Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH & CODE for use with L. It does this using a hierarchy of roles in a manner similar to what Perl 6 I do. This module, like L and L, was inspired by my work on the Perl 6 Object Space, and the 'core types' implemented there. =head2 A quick word about autobox The L module provides the ability for calling 'methods' on normal Perl values like Scalars, Arrays, Hashes and Code references. This gives the illusion that Perl's types are first-class objects. However, this is only an illusion, albeit a very nice one. I created this module because L itself does not actually provide an implementation for the Perl types but instead only provides the 'hooks' for others to add implementation too. =head2 Is this for real? or just play? Several people are using this module in serious applications and it seems to be quite stable. The underlying technologies of L and L are also considered stable. There is some performance hit, but as I am fond of saying, nothing in life is free. Note that this hit only applies to the I of methods on native Perl values, not the mere act of loading this module in your namespace. If you have any questions regarding this module, either email me, or stop by #moose on irc.perl.org and ask around. =head2 Adding additional methods B asks L to use the B namespace prefix so as to avoid stepping on the toes of other L modules. This means that if you want to add methods to a particular perl type (i.e. - monkeypatch), then you must do this: sub Moose::Autobox::SCALAR::bar { 42 } instead of this: sub SCALAR::bar { 42 } as you would with vanilla autobox. =head1 METHODS =over 4 =item B This will mixin an additional C<$role> into a certain C<$type>. The types can be SCALAR, ARRAY, HASH or CODE. This can be used to add additional methods to the types, see the F directory for some examples. =back =head1 TODO =over 4 =item More docs =item More tests =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE B Anders (Debolaz) Nor Berle Matt (mst) Trout renormalist =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Array.pm000644 000766 000766 00000013305 12233346437 020133 0ustar00rjbs000000 000000 package Moose::Autobox::Array; use Moose::Role 'with'; use Moose::Autobox; use Syntax::Keyword::Junction::All (); use Syntax::Keyword::Junction::Any (); use Syntax::Keyword::Junction::None (); use Syntax::Keyword::Junction::One (); our $VERSION = '0.15'; with 'Moose::Autobox::Ref', 'Moose::Autobox::List', 'Moose::Autobox::Indexed'; ## Array Interface sub pop { my ($array) = @_; CORE::pop @$array; } sub push { my ($array, @rest) = @_; CORE::push @$array, @rest; $array; } sub unshift { my ($array, @rest) = @_; CORE::unshift @$array, @rest; $array; } sub delete { my ($array, $index) = @_; CORE::delete $array->[$index]; } sub shift { my ($array) = @_; CORE::shift @$array; } sub slice { my ($array, $indicies) = @_; [ @{$array}[ @{$indicies} ] ]; } # NOTE: # sprintf args need to be reversed, # because the invocant is the array sub sprintf { CORE::sprintf $_[1], @{$_[0]} } ## ::List interface implementation sub head { $_[0]->[0] } sub tail { [ @{$_[0]}[ 1 .. $#{$_[0]} ] ] } sub length { my ($array) = @_; CORE::scalar @$array; } sub grep { my ($array, $sub) = @_; [ CORE::grep { $sub->($_) } @$array ]; } sub map { my ($array, $sub) = @_; [ CORE::map { $sub->($_) } @$array ]; } sub join { my ($array, $sep) = @_; $sep ||= ''; CORE::join $sep, @$array; } sub reverse { my ($array) = @_; [ CORE::reverse @$array ]; } sub sort { my ($array, $sub) = @_; $sub ||= sub { $a cmp $b }; [ CORE::sort { $sub->($a, $b) } @$array ]; } sub first { $_[0]->[0]; } sub last { $_[0]->[$#{$_[0]}]; } ## ::Indexed implementation sub at { my ($array, $index) = @_; $array->[$index]; } sub put { my ($array, $index, $value) = @_; $array->[$index] = $value; } sub exists { my ($array, $index) = @_; CORE::exists $array->[$index]; } sub keys { my ($array) = @_; [ 0 .. $#{$array} ]; } sub values { my ($array) = @_; [ @$array ]; } sub kv { my ($array) = @_; $array->keys->map(sub { [ $_, $array->[$_] ] }); } sub each { my ($array, $sub) = @_; for my $i (0 .. $#$array) { $sub->($i, $array->[ $i ]); } } sub each_key { my ($array, $sub) = @_; $sub->($_) for (0 .. $#$array); } sub each_value { my ($array, $sub) = @_; $sub->($_) for @$array; } sub each_n_values { my ($array, $n, $sub) = @_; my $it = List::MoreUtils::natatime($n, @$array); while (my @vals = $it->()) { $sub->(@vals); } return; } # end indexed sub flatten { @{$_[0]} } sub _flatten_deep { my @array = @_; my $depth = CORE::pop @array; --$depth if (defined($depth)); CORE::map { (ref eq 'ARRAY') ? (defined($depth) && $depth == -1) ? $_ : _flatten_deep( @$_, $depth ) : $_ } @array; } sub flatten_deep { my ($array, $depth) = @_; [ _flatten_deep(@$array, $depth) ]; } ## Junctions sub all { my ($array) = @_; return Syntax::Keyword::Junction::All->new(@$array); } sub any { my ($array) = @_; return Syntax::Keyword::Junction::Any->new(@$array); } sub none { my ($array) = @_; return Syntax::Keyword::Junction::None->new(@$array); } sub one { my ($array) = @_; return Syntax::Keyword::Junction::One->new(@$array); } ## Print sub print { CORE::print @{$_[0]} } sub say { CORE::print @{$_[0]}, "\n" } no Moose::Role; 1; __END__ =pod =head1 NAME Moose::Autobox::Array - the Array role =head1 SYNOPOSIS use Moose::Autobox; [ 1..5 ]->isa('ARRAY'); # true [ a..z ]->does('Moose::Autobox::Array'); # true [ 0..2 ]->does('Moose::Autobox::List'); # true print "Squares: " . [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', '); print [ 1, 'number' ]->sprintf('%d is the loneliest %s'); print ([ 1 .. 5 ]->any == 3) ? 'true' : 'false'; # prints 'true' =head1 DESCRIPTION This is a role to describe operations on the Array type. =head1 METHODS =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =back =head2 Indexed implementation =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =back =head2 List implementation =over 4 =item B =item B =item B =item B =item B =item B Note that, in both the above, $_ is in scope within the code block, as well as being passed as $_[0]. As per CORE::map and CORE::grep, $_ is an alias to the list value, so can be used to modify the list, viz: use Moose::Autobox; my $foo = [1, 2, 3]; $foo->map( sub {$_++} ); print $foo->dump; yields $VAR1 = [ 2, 3, 4 ]; =item B =item B =back =head2 Junctions =over 4 =item B =item B =item B =item B =back =over 4 =item B =item B =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Code.pm000644 000766 000766 00000004456 12233346437 017736 0ustar00rjbs000000 000000 package Moose::Autobox::Code; use Moose::Role 'with'; use Moose::Autobox; our $VERSION = '0.15'; with 'Moose::Autobox::Ref'; sub curry { my ($f, @a) = @_; return sub { $f->(@a, @_) } } sub rcurry { my ($f, @a) = @_; return sub { $f->(@_, @a) } } sub compose { my ($f, $f2, @rest) = @_; return $f if !$f2; return (sub { $f2->($f->(@_)) })->compose(@rest); } sub disjoin { my ($f, $f2) = @_; return sub { $f->(@_) || $f2->(@_) } } sub conjoin { my ($f, $f2) = @_; return sub { $f->(@_) && $f2->(@_) } } # fixed point combinators sub u { my $f = shift; sub { $f->($f, @_) }; } sub y { my $f = shift; (sub { my $h = shift; sub { $f->(($h->u)->())->(@_) } }->u)->(); } 1; __END__ =pod =head1 NAME Moose::Autobox::Code - the Code role =head1 SYNOPOSIS use Moose::Autobox; my $adder = sub { $_[0] + $_[1] }; my $add_2 = $adder->curry(2); $add_2->(2); # returns 4 # create a recursive subroutine # using the Y combinator *factorial = sub { my $f = shift; sub { my $n = shift; return 1 if $n < 2; return $n * $f->($n - 1); } }->y; factorial(10) # returns 3628800 =head1 DESCRIPTION This is a role to describe operations on the Code type. =head1 METHODS =over 4 =item B =item B =item B =item B =item B This will take a list of C<@subs> and compose them all into a single subroutine where the output of one sub will be the input of another. =item B This implements the Y combinator. =item B This implements the U combinator. =back =over 4 =item B =back =head1 SEE ALSO =over 4 =item L =item L =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Defined.pm000644 000766 000766 00000001650 12233346437 020413 0ustar00rjbs000000 000000 package Moose::Autobox::Defined; use Moose::Role 'with'; our $VERSION = '0.15'; with 'Moose::Autobox::Item'; sub defined { 1 } 1; __END__ =pod =head1 NAME Moose::Autobox::Defined - the Defined role =head1 SYNOPOSIS use Moose::Autobox; my $x; $x->defined; # false $x = 10; $x->defined; # true =head1 DESCRIPTION This is a role to describes a defined value. =head1 METHODS =over 4 =item B =back =over 4 =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Hash.pm000644 000766 000766 00000005575 12233346437 017752 0ustar00rjbs000000 000000 package Moose::Autobox::Hash; use Moose::Role 'with'; our $VERSION = '0.15'; with 'Moose::Autobox::Ref', 'Moose::Autobox::Indexed'; sub delete { my ($hash, $key) = @_; CORE::delete $hash->{$key}; } sub merge { my ($left, $right) = @_; Carp::confess "You must pass a hashref as argument to merge" unless ref $right eq 'HASH'; return { %$left, %$right }; } sub hslice { my ($hash, $keys) = @_; return { map { $_ => $hash->{$_} } @$keys }; } sub flatten { return %{$_[0]} } # ::Indexed implementation sub at { my ($hash, $index) = @_; $hash->{$index}; } sub put { my ($hash, $index, $value) = @_; $hash->{$index} = $value; } sub exists { my ($hash, $key) = @_; CORE::exists $hash->{$key}; } sub keys { my ($hash) = @_; [ CORE::keys %$hash ]; } sub values { my ($hash) = @_; [ CORE::values %$hash ]; } sub kv { my ($hash) = @_; [ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ]; } sub slice { my ($hash, $keys) = @_; return [ @{$hash}{@$keys} ]; } sub each { my ($hash, $sub) = @_; for my $key (CORE::keys %$hash) { $sub->($key, $hash->{$key}); } } sub each_key { my ($hash, $sub) = @_; $sub->($_) for CORE::keys %$hash; } sub each_value { my ($hash, $sub) = @_; $sub->($_) for CORE::values %$hash; } sub each_n_values { my ($hash, $n, $sub) = @_; my @keys = CORE::keys %$hash; my $it = List::MoreUtils::natatime($n, @keys); while (my @vals = $it->()) { $sub->(@$hash{ @vals }); } return; } # End Indexed sub print { CORE::print %{$_[0]} } sub say { CORE::print %{$_[0]}, "\n" } 1; __END__ =pod =head1 NAME Moose::Autobox::Hash - the Hash role =head1 SYNOPOSIS use Moose::Autobox; print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two' =head1 DESCRIPTION This is a role to describes a Hash value. =head1 METHODS =over 4 =item B =item B Takes a hashref and returns a new hashref with right precedence shallow merging. =item B Slices a hash but returns the keys and values as a new hashref. =item B =back =head2 Indexed implementation =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =back =over 4 =item B =item B =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Indexed.pm000644 000766 000766 00000002473 12233346437 020441 0ustar00rjbs000000 000000 package Moose::Autobox::Indexed; use Moose::Role 'requires'; our $VERSION = '0.15'; requires 'at'; requires 'put'; requires 'exists'; requires 'keys'; requires 'values'; requires 'kv'; requires 'slice'; requires qw(each each_key each_value each_n_values); 1; __END__ =pod =head1 NAME Moose::Autobox::Indexed - the Indexed role =head1 DESCRIPTION This is a role to describes an collection whose values can be accessed by a key of some kind. The role is entirely abstract, those which implement it must supply all it's methods. Currently both L and L implement this role. =head1 METHODS =over 4 =item B =back =head1 REQUIRED METHODS =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Item.pm000644 000766 000766 00000002072 12233346437 017752 0ustar00rjbs000000 000000 package Moose::Autobox::Item; use Moose::Role 'requires'; our $VERSION = '0.15'; requires 'defined'; sub dump { my $self = shift; require Data::Dumper; return Data::Dumper::Dumper($self); } *perl = \&dump; 1; __END__ =pod =head1 NAME Moose::Autobox::Item - the Item role =head1 DESCRIPTION This is the root of our role hierarchy. =head1 METHODS =over 4 =item B =item B Calls Data::Dumper::Dumper. =item B Same as B. For symmetry with Perl6's .perl method. Like &print with newline. =item B =back =head1 REQUIRED METHODS =over 4 =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/List.pm000644 000766 000766 00000003251 12233346437 017767 0ustar00rjbs000000 000000 package Moose::Autobox::List; use Moose::Role 'with', 'requires'; use Moose::Autobox; our $VERSION = '0.15'; with 'Moose::Autobox::Value'; requires 'head'; requires 'tail'; requires 'length'; requires 'join'; requires 'grep'; requires 'map'; requires 'sort'; requires 'reverse'; sub reduce { my ($array, $func) = @_; my $a = $array->values; my $acc = $a->head; $a->tail->map(sub { $acc = $func->($acc, $_) }); return $acc; } sub zip { my ($array, $other) = @_; ($array->length < $other->length ? $other : $array) ->keys ->map(sub { [ $array->at($_), $other->at($_) ] }); } 1; __END__ =pod =head1 NAME Moose::Autobox::List - the List role =head1 DESCRIPTION This is a role to describes a List interface. This is not meant to be any specific Perl type, but instead an interface that certain Perl types might implement. Currenly only L implements this. =head1 METHODS =over 4 =item B =item B =back =over 4 =item B =back =head1 REQUIRED METHODS =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Number.pm000644 000766 000766 00000002254 12233346437 020306 0ustar00rjbs000000 000000 package Moose::Autobox::Number; use Moose::Role; our $VERSION = '0.15'; with 'Moose::Autobox::Value'; sub to { return [ $_[0] .. $_[1] ] if $_[0] <= $_[1]; return [ reverse $_[1] .. $_[0] ]; } 1; __END__ =pod =head1 NAME Moose::Autobox::Number - the Number role =head1 DESCRIPTION This is a role to describes a Numeric value. =head1 METHODS =over 4 =item B Takes another number as argument and produces an array ranging from the number the method is called on to the number given as argument. In some situations, this method intentionally behaves different from the range operator in perl: $foo = [ 5 .. 1 ]; # $foo is [] $foo = 5->to(1); # $foo is [ 5, 4, 3, 2, 1 ] =back =over 4 =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Ref.pm000644 000766 000766 00000001363 12233346437 017572 0ustar00rjbs000000 000000 package Moose::Autobox::Ref; use Moose::Role 'with'; our $VERSION = '0.15'; with 'Moose::Autobox::Defined'; 1; __END__ =pod =head1 NAME Moose::Autobox::Ref - the Ref role =head1 DESCRIPTION This is a role to describes a reference value. =head1 METHODS =over 4 =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Scalar.pm000644 000766 000766 00000002441 12233346437 020261 0ustar00rjbs000000 000000 package Moose::Autobox::Scalar; use Moose::Role 'with'; our $VERSION = '0.15'; with 'Moose::Autobox::String', 'Moose::Autobox::Number'; sub flatten { $_[0] } sub first { $_[0] } sub last { $_[0] } sub print { CORE::print $_[0] } sub say { CORE::print $_[0], "\n" } 1; __END__ =pod =head1 NAME Moose::Autobox::Scalar - the Scalar role =head1 DESCRIPTION This is a role to describes a Scalar value, which is defined as the combination (union sort of) of a String and a Number. =head1 METHODS =over 4 =item B =item B =item B =item B Flattening a scalar just returns the scalar. This means that you can say: my @array = $input->flatten; # Given $input of 5, @array is (5); # Given $input of [ 5, 2, 0], @array is (5, 2, 0) =item B As per flatten. =item B As per flatten. =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/String.pm000644 000766 000766 00000003606 12233346437 020326 0ustar00rjbs000000 000000 package Moose::Autobox::String; use Moose::Role; our $VERSION = '0.15'; with 'Moose::Autobox::Value'; # perl built-ins sub lc { CORE::lc $_[0] } sub lcfirst { CORE::lcfirst $_[0] } sub uc { CORE::uc $_[0] } sub ucfirst { CORE::ucfirst $_[0] } sub chomp { CORE::chomp $_[0] } sub chop { CORE::chop $_[0] } sub reverse { CORE::reverse $_[0] } sub length { CORE::length $_[0] } sub lines { [ CORE::split '\n', $_[0] ] } sub words { [ CORE::split ' ', $_[0] ] } sub index { return CORE::index($_[0], $_[1]) if scalar @_ == 2; return CORE::index($_[0], $_[1], $_[2]); } sub rindex { return CORE::rindex($_[0], $_[1]) if scalar @_ == 2; return CORE::rindex($_[0], $_[1], $_[2]); } sub split { return [ CORE::split($_[1], $_[0]) ] if scalar @_ == 2; return [ CORE::split($_[1], $_[0], $_[2]) ]; } 1; __END__ =pod =head1 NAME Moose::Autobox::String - the String role =head1 SYNOPOSIS use Moose::Autobox; "Hello World"->uc; # HELLO WORLD =head1 DESCRIPTION This is a role to describes a String value. =head1 METHODS =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B $string->split($pattern); =item B This is equivalent to splitting on space. =item B This is equivalent to splitting on newlines. =back =over 4 =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Undef.pm000644 000766 000766 00000001574 12233346437 020123 0ustar00rjbs000000 000000 package Moose::Autobox::Undef; use Moose::Role 'with'; our $VERSION = '0.15'; with 'Moose::Autobox::Item'; sub defined { 0 } 1; __END__ =pod =head1 NAME Moose::Autobox::Undef - the Undef role =head1 SYNOPOSIS use Moose::Autobox; my $x; $x->defined; # false =head1 DESCRIPTION This is a role to describes a undefined value. =head1 METHODS =over 4 =item B =back =over 4 =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/lib/Moose/Autobox/Value.pm000644 000766 000766 00000001757 12233346437 020141 0ustar00rjbs000000 000000 package Moose::Autobox::Value; use Moose::Role 'with'; our $VERSION = '0.15'; with 'Moose::Autobox::Defined'; sub do { my ($self, $block) = @_; local $_ = $self; $block->($self); } 1; __END__ =pod =head1 NAME Moose::Autobox::Value - the Value role =head1 SYNOPOSIS use Moose::Autobox; # execute a sub on the value print 10->do(sub { $_ * $_ }); # prints 100 =head1 DESCRIPTION This is a role to describes a defined (non-reference) Perl value. =head1 METHODS =over 4 =item B =item B =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Moose-Autobox-0.15/examples/tic_tac_toe.pl000644 000766 000766 00000003571 11264641513 017676 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Moose::Autobox; use Moose::Autobox::Undef; sub print_board { my ($b) = @_; my $count = 0; $b->map(sub { print("$_ \t"); print("\n") unless ((++$count) % 3); }); } my $board = [ ('.') x 9 ]; print_board($board); my $choice = [ 1 .. 9 ]->any; my $player = 'X'; while ($board->any eq '.') { INPUT: { print("Player ($player), enter the Position [1-9]: "); my $in = <>; unless ($in == $choice) { print "\n\tPlease enter a value within 1-9\n\n"; redo INPUT; } my $idx = $in - 1; if ($board->[$idx] ne '.') { print "\n\tElement already entered at $in\n"; redo INPUT; } $board->[$idx] = $player; } print_board($board); [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ], [ 0, 3, 6 ], [ 1, 4, 7 ], [ 2, 5, 8 ], [ 0, 4, 8 ], [ 2, 4, 6 ], ]->map(sub { my $row = $board->slice($_); if (($row->all eq 'X') || ($row->all eq 'O')) { print("\n\tPlayer ($player) Wins\n"); exit; } }); $player = $player eq 'X' ? 'O' : 'X'; } =pod =head1 NAME tic_tac_toe.pl - Tic-Tac-Toe =head1 DESCRIPTION This is a Moose::Autobox port of a perl6 implementation of the classic Tic-Tac-Toe game. This uses a modified version of the one Rob Kinyon created L. =head1 AUTHOR Stevan Little, Estevan@iinteractive.comE =head1 ACKNOLEDGEMENTS This code was ported from the version in the Pugs examples/ directory. The authors of that were: mkirank L Rob Kinyon L Stevan Little, Estevan@iinteractive.comE Audrey Tang =cut Moose-Autobox-0.15/examples/units/000755 000766 000766 00000000000 12233346513 016217 5ustar00rjbs000000 000000 Moose-Autobox-0.15/examples/units/bytes.pl000644 000766 000766 00000003104 11264641513 017701 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Moose::Autobox; { package # hide from PAUSE Units::Bytes; use Moose::Role; use Moose::Autobox; sub bytes { $_[0] } sub kilobytes { $_[0] * 1024 } sub megabytes { $_[0] * 1024->kilobytes } sub gigabytes { $_[0] * 1024->megabytes } sub terabytes { $_[0] * 1024->gigabytes } { no warnings 'once'; # << squelch the stupid "used only once, maybe typo" warnings *byte = \&bytes; *kilobyte = \&kilobytes; *megabyte = \&megabytes; *gigabyte = \&gigabytes; *terabyte = \&terabytes; } } Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Bytes'); $\ = "\n"; print "5 kilobytes are " . 5->kilobytes . " bytes"; print "2 megabytes are " . 2->megabytes . " bytes"; print "1 gigabyte is " . 1->gigabyte . " bytes"; print "2 terabyes are " . 2->terabytes . " bytes"; =pod =head1 NAME Unit::Bytes =head1 SYNOPSIS Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Bytes'); print "5 kilobytes are " . 5->kilobytes . " bytes"; print "2 megabytes are " . 2->megabytes . " bytes"; print "1 gigabyte is " . 1->gigabyte . " bytes"; print "2 terabyes are " . 2->terabytes . " bytes"; =head1 DESCRIPTION This is a Moose::Autobox port of the perl6 vmethods example. =head1 AUTHOR Stevan Little, Estevan@iinteractive.comE =head1 ACKNOLEDGEMENTS This code was ported from the version in the Pugs examples/vmethods/ directory. See that for original author information. =cut Moose-Autobox-0.15/examples/units/time.pl000644 000766 000766 00000004260 11264641513 017515 0ustar00rjbs000000 000000 #!/usr/bin/perl use strict; use warnings; use Moose::Autobox; { package # hide me from PAUSE Units::Time; use Moose::Role; use Moose::Autobox; sub seconds { $_[0] } sub minutes { $_[0] * 60 } sub hours { $_[0] * 60->minutes } sub days { $_[0] * 24->hours } sub weeks { $_[0] * 7->days } sub years { $_[0] * 365->days } sub centuries { $_[0] * 10->years } sub ago { my ($self, $time) = @_; $time ||= time(); $time - $self; } sub since { my ($self, $time) = @_; $time ||= time(); $time + $self; } { no warnings 'once'; # singular versions *second = \&seconds; *minute = \&minutes; *hour = \&hours; *day = \&days; *week = \&weeks; *year = \&years; *century = \¢uries; *til = \&ago; *from_now = \&since; } sub as_string { scalar localtime $_[0] } } Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Time'); $\ = "\n"; print "2 days ago was : " . 2->days->ago->as_string; print "3 weeks from now will be : " . 3->weeks->from_now->as_string; my $one_week_ago = 1->week->ago; print "1 day until 1 week ago : " . 1->day->til($one_week_ago)->as_string; print "2 years since 1 week ago : " . 2->years->since($one_week_ago)->as_string; =pod =head1 NAME Unit::Time =head1 SYNOPSIS Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Time'); print "2 days ago was : " . 2->days->ago->as_string; print "3 weeks from now will be : " . 3->weeks->from_now->as_string; print "1 day until 1 week ago : " . 1->day->til(1->week->ago)->as_string; print "2 years since 1 week ago : " . 2->years->since(1->week->ago)->as_string; =head1 DESCRIPTION This is a Moose::Autobox port of the perl6 vmethods example. =head1 AUTHOR Stevan Little, Estevan@iinteractive.comE =head1 ACKNOLEDGEMENTS This code was ported from the version in the Pugs examples/vmethods/ directory. See that for original author information. =cut