From: Stevan Little Date: Fri, 9 Jun 2006 17:50:17 +0000 (+0000) Subject: foo X-Git-Tag: 0_02~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMoose-Autobox.git;a=commitdiff_plain;h=260cc81f7ab424f417900ab1c44b734b339f9d9e foo --- diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..7d0b930 --- /dev/null +++ b/Build.PL @@ -0,0 +1,26 @@ +use Module::Build; + +use strict; + +my $build = Module::Build->new( + module_name => 'Moose::Autobox', + license => 'perl', + requires => { + 'autobox' => '1.03', + 'Moose' => '0.09_02', + }, + optional => { + }, + build_requires => { + 'Test::More' => '0.62', + 'Test::Exception' => '0.21', + }, + create_makefile_pl => 'traditional', + recursive_test_files => 1, + add_to_cleanup => [ + 'META.yml', '*.bak', '*.gz', 'Makefile.PL', + ], +); + +$build->create_build_script; + diff --git a/Changes b/Changes new file mode 100644 index 0000000..64aa008 --- /dev/null +++ b/Changes @@ -0,0 +1 @@ +Revision history for Perl extension Moose::Autobox \ No newline at end of file diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..92ed5d2 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,29 @@ +Build.PL +Changes +Makefile.PL +META.yml +MANIFEST +MANIFEST.SKIP +README +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 +t/000_load.t +t/001_basic.t +t/002_example.t +t/003_p6_example.t +t/004_list_compressions.t +t/005_string.t +t/pod.t +t/pod_coverage.t diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..3de3ebc --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,19 @@ +^_build +^Build$ +^blib +~$ +\.bak$ +^MANIFEST\.SKIP$ +CVS +\.svn +\.DS_Store +cover_db +\..*\.sw.?$ +^Makefile$ +^pm_to_blib$ +^MakeMaker-\d +^blibdirs$ +\.old$ +^#.*#$ +^\.# +^TODO$ \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..86bb034 --- /dev/null +++ b/README @@ -0,0 +1,30 @@ +Moose::Autobox version 0.01 +=========================== + +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 + +COPYRIGHT AND LICENCE + +Copyright (C) 2006 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. + diff --git a/lib/Moose/Autobox.pm b/lib/Moose/Autobox.pm index 599e3a0..42e0dd6 100644 --- a/lib/Moose/Autobox.pm +++ b/lib/Moose/Autobox.pm @@ -70,16 +70,21 @@ Moose::Autobox - autoboxed for her pleasure =head1 DESCRIPTION =head1 ROLES - - Item | - Undef | - Defined | - Scalar* <-|- String, Number <--+ - Ref | |-- Value - Array* <-|- List <------------+ - Hash* | - Code* | - + + +------------------------+-------------------------------+ + | Identity | Behavioral | + +------------------------+-------------------------------+ + | Item | | + | Undef | | + | Defined | | + | Scalar* <-|- String, Number <--+ | + | Ref | |-- Value | + | Array* <-|- List <------------+ | + | Hash* | | + | Code* | | + | | | + +------------------------+-------------------------------+ + * indicates actual autoboxed types =head1 NOTES diff --git a/lib/Moose/Autobox/Array.pm b/lib/Moose/Autobox/Array.pm index 6d4c1e8..6bfda4a 100644 --- a/lib/Moose/Autobox/Array.pm +++ b/lib/Moose/Autobox/Array.pm @@ -47,16 +47,6 @@ sub sprintf { CORE::sprintf $_[1], @{$_[0]} } sub head { $_[0]->[0] } sub tail { [ @{$_[0]}[ 1 .. $#{$_[0]} ] ] } -sub at { - my ($array, $index) = @_; - $array->[$index]; -} - -sub put { - my ($array, $index, $value) = @_; - $array->[$index] = $value; -} - sub length { my ($array) = @_; CORE::scalar @$array; @@ -89,11 +79,17 @@ sub sort { [ CORE::sort { $sub->($a, $b) } @$array ]; } -# ::Value requirement +## ::Indexed implementation -sub print { CORE::print @{$_[0]} } +sub at { + my ($array, $index) = @_; + $array->[$index]; +} -## ::Indexed implementation +sub put { + my ($array, $index, $value) = @_; + $array->[$index] = $value; +} sub exists { my ($array, $index) = @_; @@ -134,6 +130,66 @@ Moose::Autobox::Array - the Array role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=item B + +=item B + +=item B + +=item B + +=item B + +=item B + +=back + +=head2 Indexed + +=over 4 + +=item B + +=item B + +=item B + +=item B + +=item B + +=item B + +=back + +=head2 List + +=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 diff --git a/lib/Moose/Autobox/Code.pm b/lib/Moose/Autobox/Code.pm index 1d6b3f3..aa694cb 100644 --- a/lib/Moose/Autobox/Code.pm +++ b/lib/Moose/Autobox/Code.pm @@ -55,6 +55,24 @@ Moose::Autobox::Code - the Code role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=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 diff --git a/lib/Moose/Autobox/Defined.pm b/lib/Moose/Autobox/Defined.pm index ecb06cc..e8c285b 100644 --- a/lib/Moose/Autobox/Defined.pm +++ b/lib/Moose/Autobox/Defined.pm @@ -24,6 +24,16 @@ Moose::Autobox::Defined - the Defined role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=item B + +=back + =head1 BUGS All complex software has bugs lurking in it, and this module is no diff --git a/lib/Moose/Autobox/Hash.pm b/lib/Moose/Autobox/Hash.pm index 997440d..f8766b9 100644 --- a/lib/Moose/Autobox/Hash.pm +++ b/lib/Moose/Autobox/Hash.pm @@ -6,8 +6,6 @@ our $VERSION = '0.01'; with 'Moose::Autobox::Ref', 'Moose::Autobox::Indexed'; - - sub delete { my ($hash, $key) = @_; CORE::delete $hash->{$key}; @@ -64,6 +62,34 @@ Moose::Autobox::Hash - the Hash role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=item B + +=back + +=head2 Indexed + +=over 4 + +=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 diff --git a/lib/Moose/Autobox/Indexed.pm b/lib/Moose/Autobox/Indexed.pm index 3f03fec..d3706cf 100644 --- a/lib/Moose/Autobox/Indexed.pm +++ b/lib/Moose/Autobox/Indexed.pm @@ -29,6 +29,32 @@ Moose::Autobox::Indexed - the Indexed role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=back + +=head1 REQUIRED METHODS + +=over 4 + +=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 diff --git a/lib/Moose/Autobox/Item.pm b/lib/Moose/Autobox/Item.pm index 00b40b6..0cb2092 100644 --- a/lib/Moose/Autobox/Item.pm +++ b/lib/Moose/Autobox/Item.pm @@ -22,6 +22,22 @@ Moose::Autobox::Item - the Item role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=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 diff --git a/lib/Moose/Autobox/List.pm b/lib/Moose/Autobox/List.pm index 2c45a4f..b3f9048 100644 --- a/lib/Moose/Autobox/List.pm +++ b/lib/Moose/Autobox/List.pm @@ -54,6 +54,40 @@ Moose::Autobox::List - the List role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=item B + +=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 diff --git a/lib/Moose/Autobox/Number.pm b/lib/Moose/Autobox/Number.pm index e45d14d..a2e30ad 100644 --- a/lib/Moose/Autobox/Number.pm +++ b/lib/Moose/Autobox/Number.pm @@ -22,6 +22,14 @@ Moose::Autobox::Number - the Number role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=back + =head1 BUGS All complex software has bugs lurking in it, and this module is no diff --git a/lib/Moose/Autobox/Ref.pm b/lib/Moose/Autobox/Ref.pm index f4a2562..42f3047 100644 --- a/lib/Moose/Autobox/Ref.pm +++ b/lib/Moose/Autobox/Ref.pm @@ -22,6 +22,14 @@ Moose::Autobox::Ref - the Ref role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=back + =head1 BUGS All complex software has bugs lurking in it, and this module is no diff --git a/lib/Moose/Autobox/Scalar.pm b/lib/Moose/Autobox/Scalar.pm index ca80a79..5fe4ec9 100644 --- a/lib/Moose/Autobox/Scalar.pm +++ b/lib/Moose/Autobox/Scalar.pm @@ -5,10 +5,6 @@ our $VERSION = '0.01'; with 'Moose::Autobox::String', 'Moose::Autobox::Number'; - -# ::Value requirement - -sub print { CORE::print $_[0] } 1; @@ -27,6 +23,14 @@ Moose::Autobox::Scalar - the Scalar role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=back + =head1 BUGS All complex software has bugs lurking in it, and this module is no diff --git a/lib/Moose/Autobox/String.pm b/lib/Moose/Autobox/String.pm index 6e224a4..09d63a6 100644 --- a/lib/Moose/Autobox/String.pm +++ b/lib/Moose/Autobox/String.pm @@ -39,6 +39,32 @@ Moose::Autobox::String - the String role =head1 DESCRIPTION +=head1 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 diff --git a/lib/Moose/Autobox/Undef.pm b/lib/Moose/Autobox/Undef.pm index 3876644..62a6bc8 100644 --- a/lib/Moose/Autobox/Undef.pm +++ b/lib/Moose/Autobox/Undef.pm @@ -24,6 +24,16 @@ Moose::Autobox::Undef - the Undef role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=item B + +=back + =head1 BUGS All complex software has bugs lurking in it, and this module is no diff --git a/lib/Moose/Autobox/Value.pm b/lib/Moose/Autobox/Value.pm index e3c88ed..d63316f 100644 --- a/lib/Moose/Autobox/Value.pm +++ b/lib/Moose/Autobox/Value.pm @@ -5,8 +5,6 @@ our $VERSION = '0.01'; with 'Moose::Autobox::Defined'; -requires 'print'; - sub do { my ($self, $block) = @_; local $_ = $self; @@ -34,6 +32,16 @@ Moose::Autobox::Value - the Value role =head1 DESCRIPTION +=head1 METHODS + +=over 4 + +=item B + +=item B + +=back + =head1 BUGS All complex software has bugs lurking in it, and this module is no diff --git a/t/001_basic.t b/t/001_basic.t index 3cba7b3..beb218c 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 44; +use Test::More tests => 55; BEGIN { use_ok('Moose::Autobox'); @@ -42,7 +42,10 @@ is_deeply( '... 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 }); @@ -50,8 +53,7 @@ is_deeply( [ $compose->() ], [ 1, 2 ], '... got the right return value for compose'); - - + # ARRAY my $a = [ 4, 2, 6, 78, 101, 2, 3 ]; @@ -81,6 +83,7 @@ $a->grep(sub { $_ < 50 }), 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'); @@ -144,10 +147,27 @@ $a->kv, 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'); +[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'); # Hash @@ -165,5 +185,26 @@ $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'); + + diff --git a/t/003_p6_example.t b/t/003_p6_example.t index 711d808..65845a5 100644 --- a/t/003_p6_example.t +++ b/t/003_p6_example.t @@ -22,7 +22,7 @@ BEGIN { sub terabytes { $_[0] * 1024->gigabytes } { - no warnings; # << squelch the stupid "used only once, maybe typo" warnings + no warnings 'once'; # << squelch the stupid "used only once, maybe typo" warnings *byte = \&bytes; *kilobyte = \&kilobytes; *megabyte = \&megabytes; diff --git a/t/005_string.t b/t/005_string.t index 3926a38..1a33470 100644 --- a/t/005_string.t +++ b/t/005_string.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 16; use Test::Exception; BEGIN { @@ -39,5 +39,7 @@ 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('World'), 13, '... got the correct right index'); #diag CORE::rindex('Hello World, Hello', 'Hello'); diff --git a/t/pod.t b/t/pod.t new file mode 100644 index 0000000..4ae1af3 --- /dev/null +++ b/t/pod.t @@ -0,0 +1,11 @@ +#!/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(); diff --git a/t/pod_coverage.t b/t/pod_coverage.t new file mode 100644 index 0000000..2dd2031 --- /dev/null +++ b/t/pod_coverage.t @@ -0,0 +1,11 @@ +#!/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(); \ No newline at end of file