6 use Test::More tests => 62;
24 my ($self, $other) = @_;
25 not $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);
78 with 'Comparable', 'Printable';
80 has 'amount' => (is => 'rw', isa => 'Num', default => 0);
83 my ($self, $other) = @_;
84 $self->amount <=> $other->amount;
89 sprintf '$%0.2f USD' => $self->amount
93 ok(US::Currency->does('Comparable'), '... US::Currency does Comparable');
94 ok(US::Currency->does('Eq'), '... US::Currency does Eq');
95 ok(US::Currency->does('Printable'), '... US::Currency does Printable');
97 my $hundred = US::Currency->new(amount => 100.00);
98 isa_ok($hundred, 'US::Currency');
100 can_ok($hundred, 'amount');
101 is($hundred->amount, 100, '... got the right amount');
103 can_ok($hundred, 'to_string');
104 is($hundred->to_string, '$100.00 USD', '... got the right stringified value');
106 ok($hundred->does('Comparable'), '... US::Currency does Comparable');
107 ok($hundred->does('Eq'), '... US::Currency does Eq');
108 ok($hundred->does('Printable'), '... US::Currency does Printable');
110 my $fifty = US::Currency->new(amount => 50.00);
111 isa_ok($fifty, 'US::Currency');
113 can_ok($fifty, 'amount');
114 is($fifty->amount, 50, '... got the right amount');
116 can_ok($fifty, 'to_string');
117 is($fifty->to_string, '$50.00 USD', '... got the right stringified value');
119 ok($hundred->greater_than($fifty), '... 100 gt 50');
120 ok($hundred->greater_than_or_equal_to($fifty), '... 100 ge 50');
121 ok(!$hundred->less_than($fifty), '... !100 lt 50');
122 ok(!$hundred->less_than_or_equal_to($fifty), '... !100 le 50');
123 ok(!$hundred->equal_to($fifty), '... !100 eq 50');
124 ok($hundred->not_equal_to($fifty), '... 100 ne 50');
126 ok(!$fifty->greater_than($hundred), '... !50 gt 100');
127 ok(!$fifty->greater_than_or_equal_to($hundred), '... !50 ge 100');
128 ok($fifty->less_than($hundred), '... 50 lt 100');
129 ok($fifty->less_than_or_equal_to($hundred), '... 50 le 100');
130 ok(!$fifty->equal_to($hundred), '... !50 eq 100');
131 ok($fifty->not_equal_to($hundred), '... 50 ne 100');
133 ok(!$fifty->greater_than($fifty), '... !50 gt 50');
134 ok($fifty->greater_than_or_equal_to($fifty), '... !50 ge 50');
135 ok(!$fifty->less_than($fifty), '... 50 lt 50');
136 ok($fifty->less_than_or_equal_to($fifty), '... 50 le 50');
137 ok($fifty->equal_to($fifty), '... 50 eq 50');
138 ok(!$fifty->not_equal_to($fifty), '... !50 ne 50');
140 ## ... check some meta-stuff
144 my $eq_meta = Eq->meta;
145 isa_ok($eq_meta, 'Moose::Meta::Role');
147 ok($eq_meta->has_method('not_equal_to'), '... Eq has_method not_equal_to');
148 ok($eq_meta->requires_method('equal_to'), '... Eq requires_method not_equal_to');
152 my $comparable_meta = Comparable->meta;
153 isa_ok($comparable_meta, 'Moose::Meta::Role');
155 ok($comparable_meta->does_role('Eq'), '... Comparable does Eq');
157 foreach my $method_name (qw(
158 equal_to not_equal_to
159 greater_than greater_than_or_equal_to
160 less_than less_than_or_equal_to
162 ok($comparable_meta->has_method($method_name), '... Comparable has_method ' . $method_name);
165 ok($comparable_meta->requires_method('compare'), '... Comparable requires_method compare');
169 my $printable_meta = Printable->meta;
170 isa_ok($printable_meta, 'Moose::Meta::Role');
172 ok($printable_meta->requires_method('to_string'), '... Printable requires_method to_string');
176 my $currency_meta = US::Currency->meta;
177 isa_ok($currency_meta, 'Moose::Meta::Class');
179 ok($currency_meta->does_role('Comparable'), '... US::Currency does Comparable');
180 ok($currency_meta->does_role('Eq'), '... US::Currency does Eq');
181 ok($currency_meta->does_role('Printable'), '... US::Currency does Printable');
183 foreach my $method_name (qw(
185 equal_to not_equal_to
187 greater_than greater_than_or_equal_to
188 less_than less_than_or_equal_to
191 ok($currency_meta->has_method($method_name), '... US::Currency has_method ' . $method_name);