Møøse

Using Roles with Classes

package US::Currency;
use Moose;

with 'Comparable', 'Printable';

has 'amount' => (is => 'rw', isa => 'Num', default => 0);

sub compare {
    my ($self, $other) = @_;
    $self->amount <=> $other->amount;
}

sub to_string {
    my $self = shift;
    sprintf '$%0.2f USD' => $self->amount
}
Copyright © 2006 Stevan Little