Rolf Schaufelberger
2005-03-01 12:58:40 UTC
Hi,
I want to use the Maypole (Class::DBI) Classes outside Maypole (I have
some scripts, feeding my database)
So, for Maypole I have my
BeerDB.pm and some BeerDB/Pub.om, BeerDB/Beer.pm etc
To use it outside Maypole I've setup a
Beer/DBI.pm which just calls
Class::DBI::Loader to create the classes.
But now I get an compile error
invalied CODE attribute: Exported at bla/bla/BeerDB/Users.pm
(and BeerDB/Users I have: sub authenticate : Exported {..} )
adding "use attributes" changed nothing, reading the attributes man page
doesn't really help me. What's wrong ?
'Exported' isn't a built in code attribute, and must be defined in yourI want to use the Maypole (Class::DBI) Classes outside Maypole (I have
some scripts, feeding my database)
So, for Maypole I have my
BeerDB.pm and some BeerDB/Pub.om, BeerDB/Beer.pm etc
To use it outside Maypole I've setup a
Beer/DBI.pm which just calls
Class::DBI::Loader to create the classes.
But now I get an compile error
invalied CODE attribute: Exported at bla/bla/BeerDB/Users.pm
(and BeerDB/Users I have: sub authenticate : Exported {..} )
adding "use attributes" changed nothing, reading the attributes man page
doesn't really help me. What's wrong ?
your Class::DBI classes in Maypole, the Exported attribute will be
defined for you. You're getting this error since you're trying to use
those classes outside Maypole without defining the attribute.
page.It would be much cleare if they just added an example, so one can
understand what they are talking about :-)
1. Move your Maypole actions into a different file, and keep your
BeerDB:: classes plain, vanilla CDBI. It sounds like you may have
already done this. If so, are you manually requiring BeerDB::Users and
do you need to if you're using it outside Maypole?
2. Define the Exported attribute in your CDBI classes. See
"Package-specific Attribute Handling" in perldoc attributes. Or here's a
sub MODIFY_CODE_ATTRIBUTES {
}
Well, this works! Or , more precice , it's a combination of 2. and 3.BeerDB:: classes plain, vanilla CDBI. It sounds like you may have
already done this. If so, are you manually requiring BeerDB::Users and
do you need to if you're using it outside Maypole?
2. Define the Exported attribute in your CDBI classes. See
"Package-specific Attribute Handling" in perldoc attributes. Or here's a
sub MODIFY_CODE_ATTRIBUTES {
}
I've set it up now like :
==============================
package BeerDB::DBI;
use Class::DBI::Loader;
my $l = C::D::L->new ( dsn=> ..
namespace=>'BeerDB',
additional_base_classes => qw 'BeerDB::Dummy',);
package BeerDB::Dummy;
sub untaint_columns {};
sub MODIFY_CODE_ATTRIBUTES {
my ($class, $code, @attrs) = @_;
return grep $_ ne 'Exported', @attrs;
}
1;
==================================
and my application calls:
use BeerDB::DBI;
use BeerDB::Users;
...
and can use all BeerDB::* classes umodified.
Thanks.
3. Tell Class::DBI::Loader to set up your classes with a base class that
defines the Exported attribute using the 'additional_base_classes'
option. E.g. inherit from Maypole::Model::CDBI
4. Use a mechanism other than attributes to mark actions that are
public. You can do this by defining an is_public method in your Maypole
model class. If you do this you'll have to do extra work to continue
using the default Maypole actions.
HTH
--simonflk
--defines the Exported attribute using the 'additional_base_classes'
option. E.g. inherit from Maypole::Model::CDBI
4. Use a mechanism other than attributes to mark actions that are
public. You can do this by defining an is_public method in your Maypole
model class. If you do this you'll have to do extra work to continue
using the default Maypole actions.
HTH
--simonflk
Mit freundlichen GrĂ¼ssen
Rolf Schaufelberger
-------------------------------------------------------------------
plusW
Dipl. Ing. Rolf Schaufelberger Tel. 07183/ 30 54 54
Stuttgarter Str. 26 E-Mail: ***@plusw.de
73635 Rudersberg