Moose Moose - It's the new camel #15

Reuse in a different class

package String;

use Moose;

with 'Comparable';

has string => (is => 'rw', isa => 'Str', init_arg => 'string');

sub compare {
    my ($self, $value) = @_;
    return $self->string() cmp $value;
}

package main;

my $s = String->new(string => 'Houston.pm');

print $s->string . ' is greater than Houston' . "\n" if $s->greater_than('Houston');
print $s->string . ' is less than YAPC::NA in Houston' . "\n" if $s->less_than('YAPC::NA in Houston');
print $s->string . ' is equal to Houston.pm' . "\n" if $s->equal_to('Houston.pm');
Copyright © 2007 Robert Boone