Class-DBI-Plugin-Type-0.02/0040755000175000017500000000000010033044215014277 5ustar simonsimonClass-DBI-Plugin-Type-0.02/README0100644000175000017500000000210710026565313015165 0ustar simonsimonClass/DBI/Plugin/Type version 0.01 ================================== The README is used to introduce the module and provide instructions on how to install the module, any machine dependencies it may have (for example C compilers and installed libraries) and any other information that should be provided before the module is installed. A README file is required for CPAN modules since CPAN extracts the README file from a module distribution so that people browsing the archive can use it get an idea of the modules uses. It is usually a good idea to provide version information here so that people can decide whether fixes for the module are worth downloading. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: blah blah blah COPYRIGHT AND LICENCE Put the correct copyright and licence information here. Copyright (C) 2004 Simon Cozens This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Class-DBI-Plugin-Type-0.02/Makefile.PL0100644000175000017500000000107610033044131016247 0ustar simonsimonuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Class::DBI::Plugin::Type', VERSION_FROM => 'Type.pm', # finds $VERSION PREREQ_PM => { DBI => "0.94", Class::DBI => 0 }, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'Type.pm', # retrieve abstract from module AUTHOR => 'Simon Cozens ') : ()), ); Class-DBI-Plugin-Type-0.02/Changes0100644000175000017500000000050510033044157015574 0ustar simonsimonRevision history for Perl extension Class::DBI::Plugin::Type. 0.02 Thu Apr 1 17:47:23 BST 2004 - Silence warnings about statement handles - Return if already set up. - We don't need 5.8.1 0.01 Mon Mar 15 18:08:00 2004 - original version; created by h2xs 1.22 with options -AX -n Class::DBI::Plugin::Type Class-DBI-Plugin-Type-0.02/Type.pm0100644000175000017500000000354310033044210015553 0ustar simonsimonpackage Class::DBI::Plugin::Type; use strict; use warnings; our $VERSION = '0.02'; sub import { no strict 'refs'; my $caller = caller(); #if ($caller->isa("Class::DBI::mysql") and # $caller->can("column_type")) { # return; # My work here is done #} return if $caller->can("sql_dummy"); $caller->set_sql(dummy => <<''); SELECT * FROM __TABLE__ WHERE 1=0 $caller->mk_classdata("_types"); *{$caller."::column_type"} = sub { my ($self, $column) = @_; if (!$self->_types) { my $sth = $self->sql_dummy; $sth->execute; my %hash; @hash{@{$sth->{NAME}}} = map { my $info = scalar $self->db_Main->type_info($_); if ($info) { $info->{TYPE_NAME} } else { $_ } # Typeless databases (SQLite) } @{$sth->{TYPE}}; $sth->finish; $self->_types(\%hash); } return $self->_types->{$column}; } } 1; __END__ =head1 NAME Class::DBI::Plugin::Type - Determine type information for columns =head1 SYNOPSIS package Music::Artist; use base 'Class::DBI'; use Class::DBI::Plugin::Type; Music::Artist->table('artist'); Music::Artist->columns(All => qw/artistid name/); print Music::Artist->column_type("artistid"); # integer =head1 DESCRIPTION This module allows C-based classes to query their columns for data type information in a database-independent manner. =head1 SEE ALSO L =head1 AUTHOR Simon Cozens, Esimon@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright 2004 by Simon Cozens This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. This module was generously sponsored by the Perl Foundation. =cut Class-DBI-Plugin-Type-0.02/MANIFEST0100644000175000017500000000020010026565313015426 0ustar simonsimonChanges Makefile.PL MANIFEST README Type.pm t/1.t META.yml Module meta-data (added by MakeMaker) Class-DBI-Plugin-Type-0.02/META.yml0100644000175000017500000000057610033044145015557 0ustar simonsimon# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Class-DBI-Plugin-Type version: 0.02 version_from: Type.pm installdirs: site requires: Class::DBI: 0 DBI: 0.94 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.21 Class-DBI-Plugin-Type-0.02/t/0040755000175000017500000000000010033044215014542 5ustar simonsimonClass-DBI-Plugin-Type-0.02/t/1.t0100644000175000017500000000172510026565313015102 0ustar simonsimonpackage DBI::Test; use Test::More; if (!require DBD::SQLite) { plan skip_all => "Couldn't load DBD::SQLite"; } plan tests => 6; use base 'Class::DBI'; unlink 't/test.db'; DBI::Test->set_db("Main", "dbi:SQLite:dbname=t/test.db"); #DBI::Test->set_db("Main", "dbi:mysql:dbname=beerdb"); eval { DBI::Test->db_Main->do("DROP TABLE test") }; DBI::Test->db_Main->do("CREATE TABLE test ( id int not null, brewery integer, style integer, name varchar(30), url varchar(120), tasted date, score integer(2), notes text, price decimal(4,2) )"); DBI::Test->table("test"); use_ok('Class::DBI::Plugin::Type'); like(DBI::Test->column_type("notes"), qr/text|blob/, "notes is text"); is(DBI::Test->column_type("tasted"), "date", "tasted is a date"); like(DBI::Test->column_type("price"), qr/^decimal/, "price is decimal"); like(DBI::Test->column_type("id"), qr/^int/, "id is integer"); like(DBI::Test->column_type("name"), qr/^varchar/, "name is varchar");