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. I've rtfm over and over, but I haven't been successful in
> storing without the dashes. I've tried subtypes, but that didn't work.
> BTW, the values passed in to my constructor are not ONLY the 3-3-4 digit
> format, sometimes the wireless number is 2 digits, and my WirelessNumber
> attr. isa 'Str' currently. Also, I can't modify the value passed into
> my constructor, as it is used for many different tables. Any
> suggestions are greatly appreciated.
subtype 'WirelessNumber', as 'Str', where { /^\d{10}$/ or /^\d{2}$/ };
coerce 'WirelessNumber', from 'Str', via { s/-//g; $_ };
Alternately,
subtype 'DashyWirelessNumber', as 'Str', where { /^\d{3}-\d{3}-\d{4}$/ };
coerce 'WirelessNumber', from 'DashyWirelessNumber', via { s/-//g; $_ };
BTW, "I tried X but it didn't work" doesn't tell us very much, especially when
X is a whole category of possible approaches. If you're more specific it's
easier to help you.
hdp.