0.03 release
[gitmo/Moose-Autobox.git] / examples / units / bytes.pl
CommitLineData
be334002 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Moose::Autobox;
7
8{
68a5f1ac 9 package # hide from PAUSE
10 Units::Bytes;
be334002 11 use Moose::Role;
12 use Moose::Autobox;
13
14 sub bytes { $_[0] }
15 sub kilobytes { $_[0] * 1024 }
16 sub megabytes { $_[0] * 1024->kilobytes }
17 sub gigabytes { $_[0] * 1024->megabytes }
18 sub terabytes { $_[0] * 1024->gigabytes }
19
20 {
21 no warnings 'once'; # << squelch the stupid "used only once, maybe typo" warnings
22 *byte = \&bytes;
23 *kilobyte = \&kilobytes;
24 *megabyte = \&megabytes;
25 *gigabyte = \&gigabytes;
26 *terabyte = \&terabytes;
27 }
28}
29
244bd352 30Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Bytes');
be334002 31
32$\ = "\n";
33
34print "5 kilobytes are " . 5->kilobytes . " bytes";
35print "2 megabytes are " . 2->megabytes . " bytes";
36print "1 gigabyte is " . 1->gigabyte . " bytes";
37print "2 terabyes are " . 2->terabytes . " bytes";
38
68a5f1ac 39=pod
40
41=head1 NAME
42
43Unit::Bytes
44
45=head1 SYNOPSIS
46
47 Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Bytes');
48
49 print "5 kilobytes are " . 5->kilobytes . " bytes";
50 print "2 megabytes are " . 2->megabytes . " bytes";
51 print "1 gigabyte is " . 1->gigabyte . " bytes";
52 print "2 terabyes are " . 2->terabytes . " bytes";
53
54=head1 DESCRIPTION
55
56This is a Moose::Autobox port of the perl6 vmethods example.
57
58=head1 AUTHOR
59
60Stevan Little, E<lt>stevan@iinteractive.comE<gt>
61
62=head1 ACKNOLEDGEMENTS
63
64This code was ported from the version in the Pugs
65examples/vmethods/ directory. See that for original author
66information.
67
68=cut