Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Moose - ensuring a getter returns a number

by Fletch (Chancellor)
on Feb 17, 2011 at 16:03 UTC ( #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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://888745]
[ovedpo15]: good morning and thx. I forget to mention another thing: what if I need to check that my string is "hey" and ",0" for example "hey_how,0" is good. can I check it with one regex?
[ovedpo15]: I don't know what is between "hey" and ",0"

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2018-03-20 07:52 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.