[CDBI] How do I add a method to a loaded class?

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

From: Alex Aminoff
Subject: [CDBI] How do I add a method to a loaded class?
Date: 00:22 on 07 Aug 2005
This is a multi-part message in MIME format.

--===============1960002098==
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_000B_01C59AC4.91202E40"

This is a multi-part message in MIME format.

------=_NextPart_000_000B_01C59AC4.91202E40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Very basic newbie question...

I have loaded up my database into a Class::DBI structure using =
Class::DBI::Loader. Now I would like to add a method to one of the =
autogenerated classes that will calculate some stuff based on various =
data, but otherwise appear in most respects like any other column from =
the DB. I'm pretty sure I want something using MyTable->columns( TEMP =
=3D> calcfield ).

What I've tried so far, all in one file:

use Class::DBI::Loader;

my $loader =3D Class::DBI::Loader->new(...);

sub MyTable::calcfield {
 ...
}

MyTable->columns(TEMP =3D> qw/calcfield/);


This compiles, but when I later ask for MyTable->columns(), the new =
column is not there.

Thanks for any advice,

 - Alex Aminoff
  alex@xxxxxxxxx.xxx


------=_NextPart_000_000B_01C59AC4.91202E40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2668" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Very basic newbie =
question...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have loaded up my database into a =
Class::DBI=20
structure using Class::DBI::Loader. Now I would like to add a method to =
one of=20
the autogenerated classes that will calculate some stuff based on =
various data,=20
but otherwise appear in most respects like any other column from the DB. =
I'm=20
pretty sure I want something using MyTable-&gt;columns( TEMP =3D&gt; =
calcfield=20
).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>What I've tried so far, all in one=20
file:</FONT></DIV>;
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>use =
Class::DBI::Loader;<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>my $loader =3D=20
Class::DBI::Loader-&gt;new(...);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>sub MyTable::calcfield {</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</DIV>
<DIV><BR>MyTable-&gt;columns(TEMP =3D&gt; qw/calcfield/);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>This compiles, but when I later ask for MyTable-&gt;columns(), the =
new=20
column is not there.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks for any advice,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;- Alex Aminoff</DIV>
<DIV>&nbsp;&nbsp;<A=20
href=3D"mailto:alex@xxxxxxxxx.xxx">alex@xxxxxxxxx.xxx</A></DIV>;
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></FONT></BODY></HTML>

------=_NextPart_000_000B_01C59AC4.91202E40--



--===============1960002098==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

--===============1960002098==--


(message missing)

[CDBI] How do I add a method to a loaded class?
Alex Aminoff 00:22 on 07 Aug 2005

Generated at 09:40 on 09 Aug 2005 by mariachi v0.52