Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: MooseX::Declare and overload

by Haarg (Chaplain)
on Apr 01, 2010 at 16:41 UTC ( #832341=note: print w/replies, xml ) Need Help??

in reply to Re^2: MooseX::Declare and overload
in thread MooseX::Declare and overload

There is still a lot of black magic in MooseX::Declare interfering, but if you use use overload '""' => 'to_string'; instead of referencing it symbolically, it should work if to_string is defined as either a sub or a method. It will also allow subclasses to override the stringification behavior.

Replies are listed 'Best First'.
Re^4: MooseX::Declare and overload
by FunkyMonk (Canon) on Apr 01, 2010 at 17:41 UTC
    You hit the nail on the head.
    class InDeclareString is dirty { use overload '""' => 'to_string'; has val => (is => 'rw'); method to_string { sprintf "(%s)", $self->val } };

    works perfectly.

    Many thanks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://832341]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2016-10-26 16:59 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (344 votes). Check out past polls.