6 use Test::More tests => 52;
24 my ($self, $other) = @_;
25 !$self->equal_to($other);
38 my ($self, $other) = @_;
39 $self->compare($other) == 0;
43 my ($self, $other) = @_;
44 $self->compare($other) == 1;
48 my ($self, $other) = @_;
49 $self->compare($other) == -1;
52 sub greater_than_or_equal_to {
53 my ($self, $other) = @_;
54 $self->greater_than($other) || $self->equal_to($other);
57 sub less_than_or_equal_to {
58 my ($self, $other) = @_;
59 $self->less_than($other) || $self->equal_to($other);
73 has 'amount' => (is => 'rw', isa => 'Num', default => 0);
76 my ($self, $other) = @_;
77 $self->amount <=> $other->amount;
81 ok(US::Currency->does('Ord'), '... US::Currency does Ord');
82 ok(US::Currency->does('Eq'), '... US::Currency does Eq');
84 my $hundred = US::Currency->new(amount => 100.00);
85 isa_ok($hundred, 'US::Currency');
87 can_ok($hundred, 'amount');
88 is($hundred->amount, 100, '... got the right amount');
90 ok($hundred->does('Ord'), '... US::Currency does Ord');
91 ok($hundred->does('Eq'), '... US::Currency does Eq');
93 my $fifty = US::Currency->new(amount => 50.00);
94 isa_ok($fifty, 'US::Currency');
96 can_ok($fifty, 'amount');
97 is($fifty->amount, 50, '... got the right amount');
99 ok($hundred->greater_than($fifty), '... 100 gt 50');
100 ok($hundred->greater_than_or_equal_to($fifty), '... 100 ge 50');
101 ok(!$hundred->less_than($fifty), '... !100 lt 50');
102 ok(!$hundred->less_than_or_equal_to($fifty), '... !100 le 50');
103 ok(!$hundred->equal_to($fifty), '... !100 eq 50');
104 ok($hundred->not_equal_to($fifty), '... 100 ne 50');
106 ok(!$fifty->greater_than($hundred), '... !50 gt 100');
107 ok(!$fifty->greater_than_or_equal_to($hundred), '... !50 ge 100');
108 ok($fifty->less_than($hundred), '... 50 lt 100');
109 ok($fifty->less_than_or_equal_to($hundred), '... 50 le 100');
110 ok(!$fifty->equal_to($hundred), '... !50 eq 100');
111 ok($fifty->not_equal_to($hundred), '... 50 ne 100');
113 ok(!$fifty->greater_than($fifty), '... !50 gt 50');
114 ok($fifty->greater_than_or_equal_to($fifty), '... !50 ge 50');
115 ok(!$fifty->less_than($fifty), '... 50 lt 50');
116 ok($fifty->less_than_or_equal_to($fifty), '... 50 le 50');
117 ok($fifty->equal_to($fifty), '... 50 eq 50');
118 ok(!$fifty->not_equal_to($fifty), '... !50 ne 50');
120 ## ... check some meta-stuff
124 my $eq_meta = Eq->meta;
125 isa_ok($eq_meta, 'Moose::Meta::Role');
127 ok($eq_meta->has_method('not_equal_to'), '... Eq has_method not_equal_to');
128 ok($eq_meta->requires_method('equal_to'), '... Eq requires_method not_equal_to');
132 my $ord_meta = Ord->meta;
133 isa_ok($ord_meta, 'Moose::Meta::Role');
135 ok($ord_meta->does_role('Eq'), '... Ord does Eq');
137 foreach my $method_name (qw(
138 equal_to not_equal_to
139 greater_than greater_than_or_equal_to
140 less_than less_than_or_equal_to
142 ok($ord_meta->has_method($method_name), '... Ord has_method ' . $method_name);
145 ok($ord_meta->requires_method('compare'), '... Ord requires_method compare');
149 my $currency_meta = US::Currency->meta;
150 isa_ok($currency_meta, 'Moose::Meta::Class');
152 ok($currency_meta->does_role('Ord'), '... US::Currency does Ord');
153 ok($currency_meta->does_role('Eq'), '... US::Currency does Eq');
155 foreach my $method_name (qw(
157 equal_to not_equal_to
159 greater_than greater_than_or_equal_to
160 less_than less_than_or_equal_to
162 ok($currency_meta->has_method($method_name), '... US::Currency has_method ' . $method_name);