6 use Test::More tests => 8;
10 use_ok('Moose::Autobox');
15 This comes from one of the examples in the Pugs distro.
25 sub kilobytes { $_[0] * 1024 }
26 sub megabytes { $_[0] * 1024->kilobytes }
27 sub gigabytes { $_[0] * 1024->megabytes }
28 sub terabytes { $_[0] * 1024->gigabytes }
31 no warnings 'once'; # << squelch the stupid "used only once, maybe typo" warnings
33 *kilobyte = \&kilobytes;
34 *megabyte = \&megabytes;
35 *gigabyte = \&gigabytes;
36 *terabyte = \&terabytes;
40 Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Bytes');
43 ::dies_ok { 10->bytes } '... cannot do the autoboxing lexically';
49 is(5->bytes, 5, '... got 5 bytes');
50 is(5->kilobytes, 5120, '... got 5 kilobytes');
51 is(2->megabytes, 2097152, '... got 2 megabytes');
52 is(1->gigabyte, 1073741824, '... got 1 gigabyte');
53 is(2->terabytes, 2199023255552, '... got 2 terabyte');
57 dies_ok { 5->bytes } '... no longer got 5 bytes';