RE: Inflating and deflating

[prev] [thread] [next] [Date index for 2005/02/08]

From: Addison, Mark
Subject: RE: Inflating and deflating
Date: 11:07 on 08 Feb 2005
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&nbsp; Sent: Sat 05/02/2005 23:42<BR>
&gt; lists@xxxxxxxx.xxx wrote:<BR>
&gt; &gt;&gt;My problem is that I want to be able to call $object-&gt;email=
( $email )<BR>
&gt; &gt;&gt;a plain text scalar and have it do the right thing.<BR>
&gt; &gt;<BR>
&gt; &gt; This can be accomplished with triggers, but it is somewhat comple=
x and<BR>
&gt; &gt; means forgoing the inflate/deflate mechanism. One approach:<BR>
&gt; &gt;<BR>
&gt; &gt; <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>
&gt;<BR>
&gt; I did something similar to accomplish this, which I find easier to rea=
d<BR>
&gt; but still kind of a workaround.&nbsp; I used the accessor_name sub to =
give my<BR>
&gt; column's accessor a name like &quot;email_value&quot; instead of email=
.&nbsp; Then I<BR>
&gt; wrote my own email accessor that does exactly what I want and calls<BR>
&gt; 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>
&nbsp;sub email {<BR>
&nbsp;&nbsp;&nbsp;&nbsp; $_[1] =3D Mail::Address-&gt;parse($_[1])<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( exists($_[1]) &amp;&a=
mp; ref($_[1]) ne 'Mail::Address' );<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp; return shift-&gt;_email_accessor(@_);<BR>
&nbsp;}<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--

Inflating and deflating
Simon Wilcox 19:19 on 05 Feb 2005

RE: Inflating and deflating
22:39 on 05 Feb 2005

Re: Inflating and deflating
Perrin Harkins 23:42 on 05 Feb 2005

Solved // RE: Inflating and deflating
Simon Wilcox 23:17 on 06 Feb 2005

RE: Inflating and deflating
Addison, Mark 11:07 on 08 Feb 2005

RE: Inflating and deflating
Perrin Harkins 16:21 on 08 Feb 2005

RE: Inflating and deflating
Addison, Mark 17:52 on 10 Feb 2005

RE: Inflating and deflating
Perrin Harkins 18:03 on 10 Feb 2005

RE: Inflating and deflating
Addison, Mark 12:40 on 14 Feb 2005

RE: Inflating and deflating
Perrin Harkins 20:19 on 14 Feb 2005

RE: Inflating and deflating
Addison, Mark 17:21 on 15 Feb 2005

Generated at 17:31 on 15 Feb 2005 by mariachi v0.52