Re: abstract search count

[prev] [thread] [next] [Date index for 2004/06/17]

From: Jean-Christophe Zeus
Subject: Re: abstract search count
Date: 13:33 on 17 Jun 2004
On Jun 17, 2004, at 12:53 PM, Stephen Quinney wrote:

> It was sort of thinking out loud really, I noticed that Maypole makes
> use of the 'Exported' attribute and I was wondering if this would be a
> place to do something similar.

Thanks for the hint! That saved me a lot of time figuring out how to 
write package-specific attribute handlers: Maypole::Model::Base 
contains the crucial code.

So here is my second prototype:

package Class::DBI::Plugin;
use attributes ();
our %remember;
sub MODIFY_CODE_ATTRIBUTES { $remember{ $_[1] } = $_[2]; () }
sub FETCH_CODE_ATTRIBUTES  { $remember{ $_[1] } }
sub import
{
   my $class  = shift;
   my $caller = caller;
   no strict 'refs';
   for my $symname ( keys %{ "$class\::" } ) {
     local *sym = ${ "$class\::" }{ $symname };
     *{ "$caller\::$symname" } = \&sym
       if defined( &sym )
       and grep $_ eq 'Exported', attributes::get( \&sym );
   }
}

package Class::DBI::Plugin::SubClass;
use base 'Class::DBI::Plugin';
sub foo : Exported { print "inside foo()\n" }
sub bar : Exported { print "inside bar()\n" }
sub baz { print "inside baz()\n" }

# In a class inheriting form Class::DBI...
package Test;
use Class::DBI::Plugin::SubClass;

package main;
Test::foo();
Test::bar();
Test::baz(); # fails

__END__

I think this approach is _both_ convenient and reasonably safe for 
plugin writers.
        -- 
        J.-C Zeus (mail@xxxxxx.xxx)

(message missing)

abstract search count
Jean-Christophe Zeus 07:46 on 11 Jun 2004

RE: abstract search count
Jim Helm 16:15 on 14 Jun 2004

Re: abstract search count
Jean-Christophe Zeus 14:45 on 16 Jun 2004

Re: abstract search count
Tony Bowden 07:01 on 17 Jun 2004

Re: abstract search count
Jean-Christophe Zeus 08:49 on 17 Jun 2004

Re: abstract search count
Tony Bowden 09:11 on 17 Jun 2004

Re: abstract search count
Jean-Christophe Zeus 09:39 on 17 Jun 2004

Re: abstract search count
Stephen Quinney 10:06 on 17 Jun 2004

Re: abstract search count
Jean-Christophe Zeus 10:47 on 17 Jun 2004

Re: abstract search count
Stephen Quinney 10:53 on 17 Jun 2004

Re: abstract search count
Jean-Christophe Zeus 13:33 on 17 Jun 2004

Re: abstract search count
Simon Cozens 14:20 on 17 Jun 2004

Re: abstract search count
Jean-Christophe Zeus 14:26 on 17 Jun 2004

Generated at 11:35 on 01 Dec 2004 by mariachi v0.52