Add Array->each_n.
[gitmo/Moose-Autobox.git] / t / 003_p6_example.t
index 60cd248..bead570 100644 (file)
@@ -3,17 +3,23 @@
 use strict;
 use warnings;
 
-use Test::More tests => 7;
+use Test::More tests => 8;
 use Test::Exception;
 
 BEGIN {
     use_ok('Moose::Autobox');
 }
 
+=pod
+
+This comes from one of the examples in the Pugs distro.
+
+=cut
+
 {
-    package Bytes;
+    package Units::Bytes;
     use Moose::Role;
-    use autobox;
+    use Moose::Autobox;
     
     sub bytes     { $_[0]                   }    
     sub kilobytes { $_[0] * 1024            }
@@ -22,7 +28,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;    
@@ -31,20 +37,21 @@ BEGIN {
     }
 }
 
-{
-    package SCALAR;
-    use Moose;
-    with 'Bytes';
+Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Bytes');
+
+sub testing_bytes {
+    ::dies_ok { 10->bytes } '... cannot do the autoboxing lexically';
 }
 
 {
-    use autobox;
+    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';