Commit | Line | Data |
3e887aae |
1 | package Overloaded; ##no critic (Modules::RequireFilenameMatchesPackage) |
2 | |
3 | use strict; |
6b38a9b9 |
4 | |
5 | sub new { |
6 | my $class = shift; |
7 | bless { string => shift, num => shift }, $class; |
8 | } |
9 | |
6b38a9b9 |
10 | package Overloaded::Compare; |
3e887aae |
11 | |
12 | use strict; |
13 | our @ISA = qw(Overloaded); |
6b38a9b9 |
14 | |
15 | # Sometimes objects have only comparison ops overloaded and nothing else. |
16 | # For example, DateTime objects. |
17 | use overload |
ccbd73a4 |
18 | q{eq} => sub { $_[0]->{string} eq $_[1] }, |
19 | q{==} => sub { $_[0]->{num} == $_[1] }; |
6b38a9b9 |
20 | |
21 | package Overloaded::Ify; |
3e887aae |
22 | |
23 | use strict; |
24 | our @ISA = qw(Overloaded); |
6b38a9b9 |
25 | |
26 | use overload |
ccbd73a4 |
27 | q{""} => sub { $_[0]->{string} }, |
28 | q{0+} => sub { $_[0]->{num} }; |
6b38a9b9 |
29 | |
ccbd73a4 |
30 | 1; |