[Dbix-class] New module: DBIx::Class::InflateColumn::ISBN

K. J. Cheetham jamie at shadowcatsystems.co.uk
Fri May 25 16:38:16 GMT 2007


> Nice trend. I dig it.
> As I mentioned to others, join the cult, use the long version numbers:
> 0.01000....
>
Might as well follow the trend of the other cult members. ;-)

> Just out of curiosity, the deflater:
> 
>   deflate =3D> sub { return shift->common_data; },
> 
> I don't see a common_data method in B::ISBN 1.84 (Release), only in the
> 2x Dev version...maybe I'm just blind...
>
> If not, either use B::ISBN 2.00, or tweak your Makefile.PL prereq, or
> use an alternate deflate method for older versions...
>
Doh, you're right, I've just been looking at 2.00_01 too much, I'll 
change it to ->isbn for now so it'll work with both.

> Aside from the that, I have to ask what the general InflateColimn::*
> modules goals should be for DBIC.
> 
> Personally, in things like ::Currency, I always daflate back to exactly
> what _format_ I was given in the database...if I get a number, I don't
> save back anything but a number...
> 
> So, with things like ::IP and ::ISBN, what is the correct thing to do?
> Should ISBN inflate from '1565922573' but save back ->common_data (which
> is '1-56592-257-3'), or should it deflate back to the format it was
> given? (->input_isbn which is the raw input form the db/user)?
> 
> I believe IP allows the user the choose what method to use to deflate
> before saving to the DB...maybe ISBN should do the same...or maybe not.
> Just curious.
> 
One of the things I was pondering adding in the future was the option to 
specify whether it should include the hyphens or not when deflating, 
making use of the as_string([]) method.

Also, common_data returns normalised data, which does not include 
hyphens. I was just thinking about saving a few bytes by only storing 
digits and the potential 'X' by default. (Damn check digit meaning I 
can't use an int!)

But whether to use that or keep the raw data which the user entered is a 
good question... personally I'd tend to want to normalise it so it's all 
in the same format, but I dunno. Whether the X is upper or lower case is 
also a minor issue, upper seems preferred.

The option to always deflate to an ISBN13 even if the user entered an 
ISBN10 also occurred to me, though then I would need to make B::ISBN 
2.00 a prereq.

And from your other message (possibly bad of me to combine them):
> I'd also do a is_valid_checksum when inflating, and throw and exception
> if it fails...but that's just me. Maybe that's overkill.
 >
An exception is possibly overkill, but I'd still be inclined to make it 
spit out a warning at least. Or just make some kind of strict_isbn 
option which only will inflate when it's valid.

I do admit I'm not overly keen on the idea of automatically fixing the 
checksum  though.

-- 
K. J. Cheetham MPhys (hons) AMInstP
Software Developer
Shadowcat Systems Ltd.
http://www.shadowcatsystems.co.uk/



More information about the Dbix-class mailing list