package MyApp::User;
use strict;
use overload
'""' => \&stringify,
'eq' => \&cmp,
;
sub new {
my( $class, %options )= @_;
bless \%options => $class;
};
sub stringify {
my( $self )= @_;
colorize( $self->{ name }, 'red' );
};
sub cmp {
...
};
In the long run, this approach of adding more magic instead of cleanly separating display logic and business logic in your program will cause you lots of problems. Most likely you will encounter unintentional stringification. But that's an experience you'll have to make yourself.
|