some more examples
[gitmo/Moose-Autobox.git] / examples / units / bytes.t
CommitLineData
be334002 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Moose::Autobox;
7
8{
9 package Units::Bytes;
10 use Moose::Role;
11 use Moose::Autobox;
12
13 sub bytes { $_[0] }
14 sub kilobytes { $_[0] * 1024 }
15 sub megabytes { $_[0] * 1024->kilobytes }
16 sub gigabytes { $_[0] * 1024->megabytes }
17 sub terabytes { $_[0] * 1024->gigabytes }
18
19 {
20 no warnings 'once'; # << squelch the stupid "used only once, maybe typo" warnings
21 *byte = \&bytes;
22 *kilobyte = \&kilobytes;
23 *megabyte = \&megabytes;
24 *gigabyte = \&gigabytes;
25 *terabyte = \&terabytes;
26 }
27}
28
29{
30 package Moose::Autobox::SCALAR;
31 use Moose 'with';
32 with 'Units::Bytes';
33}
34
35$\ = "\n";
36
37print "5 kilobytes are " . 5->kilobytes . " bytes";
38print "2 megabytes are " . 2->megabytes . " bytes";
39print "1 gigabyte is " . 1->gigabyte . " bytes";
40print "2 terabyes are " . 2->terabytes . " bytes";
41