[Moose-commits] r7517 - in Moose-Autobox/trunk: . lib/Moose/Autobox t

debolaz at code2.0beta.co.uk debolaz at code2.0beta.co.uk
Tue Feb 3 22:30:00 GMT 2009


Author: debolaz
Date: 2009-02-03 14:30:00 -0800 (Tue, 03 Feb 2009)
New Revision: 7517

Added:
   Moose-Autobox/trunk/t/009_number.t
Modified:
   Moose-Autobox/trunk/Changes
   Moose-Autobox/trunk/lib/Moose/Autobox/Number.pm
Log:
Add 'to' to Number


Modified: Moose-Autobox/trunk/Changes
===================================================================
--- Moose-Autobox/trunk/Changes	2009-02-03 22:00:36 UTC (rev 7516)
+++ Moose-Autobox/trunk/Changes	2009-02-03 22:30:00 UTC (rev 7517)
@@ -2,6 +2,7 @@
 
 0.10
     - 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

Modified: Moose-Autobox/trunk/lib/Moose/Autobox/Number.pm
===================================================================
--- Moose-Autobox/trunk/lib/Moose/Autobox/Number.pm	2009-02-03 22:00:36 UTC (rev 7516)
+++ Moose-Autobox/trunk/lib/Moose/Autobox/Number.pm	2009-02-03 22:30:00 UTC (rev 7517)
@@ -1,10 +1,15 @@
 package Moose::Autobox::Number;
 use Moose::Role;
 
-our $VERSION = '0.09';
+our $VERSION = '0.10';
 
 with 'Moose::Autobox::Value';
-     
+
+sub to {
+    return [ $_[0] .. $_[1] ] if $_[0] <= $_[1];
+    return [ reverse $_[1] .. $_[0] ];
+}
+
 1;
 
 __END__
@@ -23,6 +28,21 @@
 
 =over 4
 
+=item B<to>
+
+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 situation, 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<meta>
 
 =back

Added: Moose-Autobox/trunk/t/009_number.t
===================================================================
--- Moose-Autobox/trunk/t/009_number.t	                        (rev 0)
+++ Moose-Autobox/trunk/t/009_number.t	2009-02-03 22:30:00 UTC (rev 7517)
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+
+BEGIN {
+    use_ok('Moose::Autobox');
+}
+
+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');
+




More information about the Moose-commits mailing list