RE: Inflating and deflating
[prev]
[thread]
[next]
[Date index for 2005/02/08]
This is a multi-part message in MIME format.
------_=_NextPart_001_01C50DCE.746D85DC
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
From: Perrin Harkins Sent: Sat 05/02/2005 23:42
> lists@xxxxxxxx.xxx wrote:
> >>My problem is that I want to be able to call $object->email( $email )
> >>a plain text scalar and have it do the right thing.
> >
> > This can be accomplished with triggers, but it is somewhat complex and
> > means forgoing the inflate/deflate mechanism. One approach:
> >
> > http://groups.kasei.com/mail/arc/cdbi-talk/2004-12/msg00019.html
>
> I did something similar to accomplish this, which I find easier to read
> but still kind of a workaround. I used the accessor_name sub to give my
> column's accessor a name like "email_value" instead of email. Then I
> wrote my own email accessor that does exactly what I want and calls
> email_value() for the database reads and writes.
I've done this kind of thing the same way, although not using
accessor_name(). As cdbi is Class::Accessor based you get an alias
method you can call, _colname_accessor, that calls the origional cdbi
version (much like SUPER in overides) e.g.
sub email {
$_[1] =3D Mail::Address->parse($_[1])
if ( exists($_[1]) && ref($_[1]) ne 'Mail::Address' );
return shift->_email_accessor(@_);
}
It works well, the warning being its a public interface level hack
(ie the accessors), and gets bipassed by some of the internals and
anything that uses get() or set(). You may or may not want that!
I think Simon's normalize approach covers more in this respect.
mark
--
This email (and any attachments) is intended solely for the individual(s) t=
o whom addressed.=20
It may contain confidential and/or legally privileged information.=20
Any statement or opinions therein are not necessarily those of ITN unless s=
pecifically stated.=20
Any unauthorised use, disclosure or copying is prohibited.=20
If you have received this email in error, please notify the sender and dele=
te it from your system.=20
Security and reliability of the e-mail and attachments are not guaranteed.=20
You must take full responsibility for virus checking.
Independent Television News Limited,=20
Registered No. 548648 England,
VAT Reg. No: GB 756 2995 81,=20
200 Gray's Inn Road, London WC1X 8XZ,
Telephone: 020 7833 3000.
------_=_NextPart_001_01C50DCE.746D85DC
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3Diso-8859-=
1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version 6.5.6980.19">
<TITLE>RE: Inflating and deflating</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=3D2>From: Perrin Harkins Sent: Sat 05/02/2005 23:42<BR>
> lists@xxxxxxxx.xxx wrote:<BR>
> >>My problem is that I want to be able to call $object->email=
( $email )<BR>
> >>a plain text scalar and have it do the right thing.<BR>
> ><BR>
> > This can be accomplished with triggers, but it is somewhat comple=
x and<BR>
> > means forgoing the inflate/deflate mechanism. One approach:<BR>
> ><BR>
> > <A HREF=3D"http://groups.kasei.com/mail/arc/cdbi-talk/2004-12/msg=
00019.html">http://groups.kasei.com/mail/arc/cdbi-talk/2004-12/msg00019.htm=
l</A><BR>
><BR>
> I did something similar to accomplish this, which I find easier to rea=
d<BR>
> but still kind of a workaround. I used the accessor_name sub to =
give my<BR>
> column's accessor a name like "email_value" instead of email=
. Then I<BR>
> wrote my own email accessor that does exactly what I want and calls<BR>
> email_value() for the database reads and writes.<BR>
<BR>
I've done this kind of thing the same way, although not using<BR>
accessor_name(). As cdbi is Class::Accessor based you get an alias<BR>
method you can call, _colname_accessor, that calls the origional cdbi<BR>
version (much like SUPER in overides) e.g.<BR>
<BR>
sub email {<BR>
$_[1] =3D Mail::Address->parse($_[1])<BR>
if ( exists($_[1]) &&a=
mp; ref($_[1]) ne 'Mail::Address' );<BR>
<BR>
return shift->_email_accessor(@_);<BR>
}<BR>
<BR>
It works well, the warning being its a public interface level hack<BR>
(ie the accessors), and gets bipassed by some of the internals and<BR>
anything that uses get() or set(). You may or may not want that!<BR>
I think Simon's normalize approach covers more in this respect.<BR>
<BR>
mark<BR>
--<BR>
<BR>
<BR>
</FONT>
</P>
<pre>This email (and any attachments) is intended solely for the individual=
(s) to whom addressed.=20
It may contain confidential and/or legally privileged information.=20
Any statement or opinions therein are not necessarily those of ITN unless s=
pecifically stated.=20
Any unauthorised use, disclosure or copying is prohibited.=20
If you have received this email in error, please notify the sender and dele=
te it from your system.=20
Security and reliability of the e-mail and attachments are not guaranteed.=20
You must take full responsibility for virus checking.
Independent Television News Limited,=20
Registered No. 548648 England,
VAT Reg. No: GB 756 2995 81,=20
200 Gray's Inn Road, London WC1X 8XZ,
Telephone: 020 7833 3000.
</pre></BODY>
</HTML>
------_=_NextPart_001_01C50DCE.746D85DC--
|
|
RE: Inflating and deflating
Addison, Mark 11:07 on 08 Feb 2005
|