Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Moose - ensuring a getter returns a number

by Fletch (Bishop)
on Feb 17, 2011 at 16:03 UTC ( [id://888745]=note: print w/replies, xml ) Need Help??


in reply to Moose - ensuring a getter returns a number

Maybe use around?

around 'now' => sub { my $orig = shift; my $self = shift; return $self->$orig( @_ ) + 0; }

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Moose - ensuring a getter returns a number
by perl5ever (Pilgrim) on Feb 17, 2011 at 20:40 UTC
    Thanks for the idea.

    Is there anything that can be done with Moose type constraints?

      Not likely, since Perl is so permissive about what is a number and what is a string, the Moose type constraint for numbers allows them to also be strings as well.

      The solution with the around is actually pretty good, or as another responder points out, make sure that the value is a number before it is actually added to your data object.

      -stvn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found