6 use Test::More tests => 7;
9 require Moose::Autobox;
13 This comes from one of the examples in the Pugs distro.
23 sub kilobytes { $_[0] * 1024 }
24 sub megabytes { $_[0] * 1024->kilobytes }
25 sub gigabytes { $_[0] * 1024->megabytes }
26 sub terabytes { $_[0] * 1024->gigabytes }
29 no warnings 'once'; # << squelch the stupid "used only once, maybe typo" warnings
31 *kilobyte = \&kilobytes;
32 *megabyte = \&megabytes;
33 *gigabyte = \&gigabytes;
34 *terabyte = \&terabytes;
38 Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Bytes');
41 ::dies_ok { 10->bytes } '... cannot do the autoboxing lexically';
47 is(5->bytes, 5, '... got 5 bytes');
48 is(5->kilobytes, 5120, '... got 5 kilobytes');
49 is(2->megabytes, 2097152, '... got 2 megabytes');
50 is(1->gigabyte, 1073741824, '... got 1 gigabyte');
51 is(2->terabytes, 2199023255552, '... got 2 terabyte');
55 dies_ok { 5->bytes } '... no longer got 5 bytes';