Class-DBI-Plugin-0.03/0040755000076500007650000000000010100222526012107 5ustar jcjcClass-DBI-Plugin-0.03/Changes0100644000076500007650000000057010100222501013372 0ustar jcjcRevision history for Perl extension Class::DBI::Plugin. 0.03 Fri Jul 23 16:47:00 - bugfix in Makefile.PL: prereq lacked version number 0.02 Mon Jul 5 22:25:00 2004 - added note in README that full tests need both DBD::SQLite and SQL::Abstract 0.01 Sat Jul 3 18:06:37 2004 - original version; created by h2xs 1.22 with options -XAn Class::DBI::Plugin -b 5.6.0 Class-DBI-Plugin-0.03/Makefile.PL0100644000076500007650000000050210100222226014050 0ustar jcjcuse 5.006; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Class::DBI::Plugin', VERSION_FROM => 'Plugin.pm', PREREQ_PM => { 'Class::DBI' => 0.90 }, ($] >= 5.005 ? (ABSTRACT_FROM => 'Plugin.pm', AUTHOR => 'Jean-Christophe Zeus ') : ()), ); Class-DBI-Plugin-0.03/MANIFEST0100644000076500007650000000023210072332710013237 0ustar jcjcChanges Makefile.PL MANIFEST Plugin.pm README t/01-require.t t/02-select.t META.yml Module meta-data (added by MakeMaker) Class-DBI-Plugin-0.03/META.yml0100644000076500007650000000052510100222526013357 0ustar jcjc# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Class-DBI-Plugin version: 0.03 version_from: Plugin.pm installdirs: site requires: Class::DBI: 0.9 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 Class-DBI-Plugin-0.03/Plugin.pm0100644000076500007650000000547110100221637013711 0ustar jcjcpackage Class::DBI::Plugin; use 5.006; use strict; use attributes (); our $VERSION = 0.03; # Code stolen from Simon Cozens (Maypole) 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 }; next unless defined &sym; # We're only in it for the subroutines &sym( $caller ), next if $symname eq 'init'; *{ "$caller\::$symname" } = \&sym if grep { defined( $_ ) and $_ eq 'Plugged' } attributes::get( \&sym ); } } 1; __END__ =head1 NAME Class::DBI::Plugin - Abstract base class for Class::DBI plugins =head1 SYNOPSIS use base 'Class::DBI::Plugin'; sub init { my $class = shift; $class->set_sql( statement_name => ... ); $class->add_trigger( ... ); $class->columns( TEMP => ... ); } sub method_name : Plugged { my $class = shift; $class->sql_statement_name( ... ); } sub this_method_is_not_exported {} =head1 DESCRIPTION Class::DBI::Plugin is an abstract base class for Class::DBI plugins. Its purpose is to make writing plugins easier. Writers of plugins should be able to concentrate on the functionality their module provides, instead of having to deal with the symbol table hackery involved when writing a plugin module. Only three things must be remembered: =over =item 1 All methods which are to exported are given the "Plugged" attribute. All other methods are not exported to the plugged-in class. =item 2 Method calls which are to be sent to the plugged-in class are put in the init() method. Examples of these are set_sql(), add_trigger() and so on. =item 3 The class parameter for the init() method and the "Plugged" methods is the plugged-in class, not the plugin class. =back =head1 CAVEATS So far this module only "sees" methods in the plugin module itself. If there is a class between the base class and the plugin class in the inheritance hierarchy, methods of this class will not be found. In other words, inherited methods will not be found. If requested, I will implement this behaviour. =head1 TODO It may be useful for plugin users to be able to choose only the plugin methods they are interested in, if there are more than one. This is not implemented yet. =head1 SEE ALSO =over =item * Class::DBI =back =head1 AUTHOR Jean-Christophe Zeus, Email@jczeus.comE with some help from Simon Cozens. Many thanks to Mark Addison for the idea with the init() method, and many thanks to Steven Quinney for the idea with the subroutine attributes. =head1 COPYRIGHT AND LICENSE Copyright (C) 2004 by Jean-Christophe Zeus This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Class-DBI-Plugin-0.03/README0100644000076500007650000000513710072334277013011 0ustar jcjcClass/DBI/Plugin version 0.01 ============================= INSTALLATION To install this module type the following: perl Makefile.PL make make test make install Note that "make test" only runs a "live" example if both DBD::SQLite and SQL::Abstract are installed. DEPENDENCIES This module requires these other modules and libraries: Class::DBI SYNOPSIS use base 'Class::DBI::Plugin'; sub init { my $class = shift; $class->set_sql( statement_name => ... ); $class->add_trigger( ... ); $class->columns( TEMP => ... ); } sub method_name : Plugged { my $class = shift; $class->sql_statement_name( ... ); } sub this_method_is_not_exported {} DESCRIPTION Class::DBI::Plugin is an abstract base class for Class::DBI plugins. Its purpose is to make writing plugins easier. Writers of plugins should be able to concentrate on the functionality their module pro- vides, instead of having to deal with the symbol table hackery involved when writing a plugin module. Only three things must be remembered: 1 All methods which are to exported are given the "Plugged" attribute. All other methods are not exported to the plugged-in class. 2 Method calls which are to be sent to the plugged-in class are put in the init() method. Examples of these are set_sql(), add_trig- ger() and so on. 3 The class parameter for the init() method and the "Plugged" methods is the plugged-in class, not the plugin class. CAVEATS So far this module only "sees" methods in the plugin module itself. If there is a class between the base class and the plugin class in the inheritance hierarchy, methods of this class will not be found. In other words, inherited methods will not be found. If requested, I will implement this behaviour. TODO It may be useful for plugin users to be able to choose only the plugin methods they are interested in, if there are more than one. This is not implemented yet. SEE ALSO o Class::DBI AUTHOR Jean-Christophe Zeus, with some help from Simon Coz- ens. Many thanks to Mark Addison for the idea with the init() method, and many thanks to Steven Quinney for the idea with the subroutine attributes. COPYRIGHT AND LICENCE Copyright (C) 2004 Jean-Christophe Zeus This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Class-DBI-Plugin-0.03/t/0040755000076500007650000000000010100222526012352 5ustar jcjcClass-DBI-Plugin-0.03/t/01-require.t0100644000076500007650000000011210072311040014416 0ustar jcjcuse strict; use Test::More tests => 1; require_ok 'Class::DBI::Plugin'; Class-DBI-Plugin-0.03/t/02-select.t0100644000076500007650000000232710072452504014247 0ustar jcjcuse strict; use Test::More; BEGIN { eval 'use DBD::SQLite; use SQL::Abstract'; plan $@ ? ( skip_all => 'needs DBD::SQLite and SQL::Abstract for testing' ) : ( tests => 1 ); } use DBI; my $db = 't/testdb'; my @dsn = ( "dbi:SQLite:dbname=$db", "", "", { autoCommit => 1 } ); DBI->connect( @dsn)->do( <<"" ); CREATE TABLE music ( id INTEGER NOT NULL PRIMARY KEY , title VARCHAR(32) ) { package Class::DBI::Plugin::AbstractCount; use base 'Class::DBI::Plugin'; use SQL::Abstract; sub init { $_[0]->set_sql( count_search_where => "SELECT COUNT(*) FROM __TABLE__ %s" ); } sub count_search_where : Plugged { my $class = shift; my ( $phrase, @bind ) = SQL::Abstract->new()->where( { @_ } ); $class->sql_count_search_where( $phrase )->select_val( @bind ); } } { package Music; use base qw( Class::DBI ); __PACKAGE__->set_db( Main => @dsn ); __PACKAGE__->table( 'music' ); __PACKAGE__->columns( Primary => qw( id ) ); __PACKAGE__->columns( All => qw( title ) ); Class::DBI::Plugin::AbstractCount->import; } for my $i ( 1 .. 50 ) { Music->create( { title => "title $i" }); } my $count = Music->count_search_where( title => [ 'title 10', 'title 20' ] ); is $count, 2, "count is 2"; END { unlink $db if -e $db }