Something along the lines of the following should work:
package Types;
use Moose::Util::TypeConstraints;
# note, need a type here, as otherwise coersions won't work if done as
a subtype of 'Str'
type Types.pcr
= where { defined $_ and $_ =~ /^\d+$/ };
coerce Types.pcr
= from Str
= via {
Excerpts from Steve's message of Fri Feb 26 09:21:05 -0500 2010:
I have a class, 'UsageDetail' which takes a CSV phone call record and
inserts it into my database. One of the attributes, 'WirelessNumber'
has dashes in it, ie: '989-555-1212'. I don't want to store the dashes
in the db.
This method works great! I was very close to getting coercion to work,
but somehow my substitution returned '2' every time. Thanks all for the
help
Steve
Something along the lines of the following should work:
package Types;
use Moose::Util::TypeConstraints;
# note, need a type here,
Excerpts from Steve's message of Fri Feb 26 09:50:51 -0500 2010:
This method works great! I was very close to getting coercion to work,
but somehow my substitution returned '2' every time. Thanks all for the
help
You were doing via { s/-//g } instead of via { s/-//g; $_ }, so you were
I've moved on to a slightly more complex situation. The same phone call
record contains two different date fields. One is a string like 'Jan
21, 2010' (incidentally, this date is repeated for each record, as it
represents the end of the billing cycle), which I have successfully
converted
I found a solution...I hooked into my already-existing 'around
BUILDARGS' and set the attribute to the returned value from
'_explodeDate', passing in the two values (call date cycle end date)
that I needed to compose a properly typed date. It's not pretty, and
I'm sure there are more
On Fri, Feb 26, 2010 at 12:52:44PM -0500, Steve wrote:
I've moved on to a slightly more complex situation. The same phone call
record contains two different date fields. One is a string like 'Jan
21, 2010' (incidentally, this date is repeated for each record, as it
represents the end