Catalyst-Model-DBI-0.32/000755 000000 001751 00000000000 12141124765 014621 5ustar00rootalex000000 000000 Catalyst-Model-DBI-0.32/lib/000755 000000 001751 00000000000 12141124764 015366 5ustar00rootalex000000 000000 Catalyst-Model-DBI-0.32/t/000755 000000 001751 00000000000 12141124764 015063 5ustar00rootalex000000 000000 Catalyst-Model-DBI-0.32/META.yml000644 000000 001751 00000001027 12141124765 016072 0ustar00rootalex000000 000000 --- abstract: unknown author: - 'Alex Pavlovic (alex.pavlovic@taskforce-1.com)' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.130880' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Catalyst-Model-DBI no_index: directory: - t - inc requires: Catalyst: 5.00 DBI: 0 DBIx::Connector: 0 MRO::Compat: 0 version: 0.32 Catalyst-Model-DBI-0.32/Changes000644 001751 001751 00000003574 12141124615 016103 0ustar00alexalex000000 000000 Revision history for Perl extension Catalyst::Model::DBI. 0.32 Fri May 03 23:23:00 2013 - make use of basic log level 0.31 Fri May 03 23:08:00 2013 - added support for log levels 0.30 Fri Apr 27 18:00:00 2012 - rewrote internals to use DBIx::Connector and updated documentation 0.29 Fri Mar 30 14:00:00 2012 - added support for settings being loaded from config file 0.28 Thu Jan 28 15:30:00 2010 - Corrected PREREQ_PM 0.27 Thu Jan 28 15:00:00 2010 - Reverted to MRO::Compat 0.26 Thu Jan 28 14:00:00 2010 - Corrected PREREQ_PM 0.25 Thu Jan 21 18:00:00 2010 - Added support for Class::C3 0.24 Sun Oct 18 19:30:00 2009 - Fixup copyright info 0.23 Fri Oct 02 10:30:00 2009 - Corrected Changes file 0.22 Fri Oct 02 10:00:00 2009 - Change from NEXT to MRO::Compat 0.21 Fri Oct 02 10:00:00 2009 - Added support for configs named either "user" or "username" and "password" or "pass" - Updated the helper to use parent instead of base 0.20 Sun Dec 07 17:36:00 2008 - fixed issue: http://rt.cpan.org/Public/Bug/Display.html?id=38121 - fixed issue: http://rt.cpan.org/Public/Bug/Display.html?id=39884 0.19 Fri Sep 07 18:00:00 2007 - cleaned up a few things 0.18 Mon May 07 18:40:00 2007 - reverting back to 0.15 as per Evan Caroll request, model behaving as expected 0.17 Mon May 07 08:00:00 2007 - made $self->_pid($$) "non lazy", fixed a few things 0.16 Sun May 06 14:48:00 2007 - added fix to support ACCEPT_CONTEXT as per issue brought up by Evan Caroll 0.15 Sun Dec 10 23:00:00 2006 - added fix to support config 0.14 Sat Jun 24 18:00:00 2006 - added additional check for stay_connected 0.13 Tue May 30 22:00:00 2006 - inherits from Catalyst::Model rather then Catalyst::Base 0.12 Tue May 30 12:00:00 2006 - made code mod_perl safe 0.11 Sun Nov 27 18:00:00 2005 - fixed a TT comment in helper class 0.10 Sun Nov 27 15:00:00 2005 - first release Catalyst-Model-DBI-0.32/MANIFEST000644 000000 001751 00000000475 12141124765 015760 0ustar00rootalex000000 000000 Changes lib/Catalyst/Helper/Model/DBI.pm lib/Catalyst/Model/DBI.pm Makefile.PL MANIFEST This list of files README t/01use.t t/02pod.t t/03podcoverage.t META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Catalyst-Model-DBI-0.32/Makefile.PL000644 001751 001751 00000000437 12140254662 016562 0ustar00alexalex000000 000000 use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Catalyst::Model::DBI', AUTHOR => 'Alex Pavlovic (alex.pavlovic@taskforce-1.com)', PREREQ_PM => { Catalyst => '5.00', DBI => 0, MRO::Compat => 0, DBIx::Connector => 0 }, VERSION_FROM => 'lib/Catalyst/Model/DBI.pm' );Catalyst-Model-DBI-0.32/README000644 001751 001751 00000005536 12141123264 015467 0ustar00alexalex000000 000000 NAME Catalyst::Model::DBI - DBI Model Class SYNOPSIS # use the helper to create a model for example perl script/myapp_create.pl model MyModel DBI dsn username password # lib/MyApp/Model/DBI.pm package MyApp::Model::DBI; use base 'Catalyst::Model::DBI'; __PACKAGE__->config( dsn => 'DBI:Pg:dbname=mydb;host=localhost', username => 'pgsql', password => '', options => { AutoCommit => 1 }, loglevel => 1 ); 1; # or load settings from a config file via Config::General for example # in your myapp.conf you could have name MyApp dsn "DBI:Pg:dbname=mydb;host=localhost" username pgsql password "" AutoCommit 1 loglevel 1 # note that config settings always override Model settings # do something with $dbh inside a controller ... my $dbh = $c->model('MyModel')->dbh; # do something with $dbh inside a model ... my $dbh = $self->dbh; #do something with DBIx::Connector connection inside a controller ... my $connection = $c->model('MyModel')->connection; #do something with DBIx::Connector connection inside a model ... my $connection = $self->connection; DESCRIPTION This is the "DBI" model class. It has been rewritten to use DBIx::Connector since it's internal code that deals with connection maintenance has already been ported into there. You now have two options for doing custom models with Catalyst. Either by using this model and any related modules as needed or by having your custom model decoupled from Catalyst and glued on using Catalyst::Model::Adaptor Some general rules are as follows. If you do not wish to use DBIx::Connector directly or DBI and setup connections in your custom models or have glue models, then use this model. If you however need models that can be re-used outside of your application or simply wish to maintain connection code yourself outside of the Catalyst, then use Catalyst::Model::Adaptor which allows you to glue outside models into your Catalyst app. METHODS new Initializes DBI connection $self->connection Returns the current DBIx::Connector connection handle. $self->dbh Returns the current database handle. $self->connect Connects to the database and returns the handle. SEE ALSO Catalyst, DBI, Catalyst::Model::Proxy, Catalyst::Model::DBI::SQL::Library AUTHOR Alex Pavlovic, "alex.pavlovic@taskforce-1.com" COPYRIGHT Copyright (c) 2005 - 2012 the Catalyst::Model::DBI "AUTHOR" as listed above. LICENSE This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. Catalyst-Model-DBI-0.32/META.json000644 000000 001751 00000001713 12141124765 016244 0ustar00rootalex000000 000000 { "abstract" : "unknown", "author" : [ "Alex Pavlovic (alex.pavlovic@taskforce-1.com)" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.130880", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Catalyst-Model-DBI", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Catalyst" : "5.00", "DBI" : "0", "DBIx::Connector" : "0", "MRO::Compat" : "0" } } }, "release_status" : "stable", "version" : "0.32" } Catalyst-Model-DBI-0.32/t/02pod.t000644 001751 001751 00000000276 12140254662 016165 0ustar00alexalex000000 000000 use Test::More; eval "use Test::Pod 1.14"; plan skip_all => 'Test::Pod 1.14 required' if $@; plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; all_pod_files_ok(); Catalyst-Model-DBI-0.32/t/01use.t000644 001751 001751 00000000202 12140254662 016163 0ustar00alexalex000000 000000 use strict; use Test::More tests => 2; BEGIN { use_ok('Catalyst::Model::DBI') } BEGIN { use_ok('Catalyst::Helper::Model::DBI') } Catalyst-Model-DBI-0.32/t/03podcoverage.t000644 001751 001751 00000000325 12140254662 017675 0ustar00alexalex000000 000000 use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@; plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; all_pod_coverage_ok(); Catalyst-Model-DBI-0.32/lib/Catalyst/000755 000000 001751 00000000000 12141124764 017152 5ustar00rootalex000000 000000 Catalyst-Model-DBI-0.32/lib/Catalyst/Helper/000755 000000 001751 00000000000 12141124764 020371 5ustar00rootalex000000 000000 Catalyst-Model-DBI-0.32/lib/Catalyst/Model/000755 000000 001751 00000000000 12141124764 020212 5ustar00rootalex000000 000000 Catalyst-Model-DBI-0.32/lib/Catalyst/Model/DBI.pm000644 001751 001751 00000011051 12141124531 021120 0ustar00alexalex000000 000000 package Catalyst::Model::DBI; use strict; use base 'Catalyst::Model'; use MRO::Compat; use mro 'c3'; use DBIx::Connector; use constant LOG_LEVEL_BASIC => 1; use constant LOG_LEVEL_INTERMEDIATE => 2; use constant LOG_LEVEL_FULL => 3; our $VERSION = '0.32'; __PACKAGE__->mk_accessors( qw/_connection _dbh/ ); =head1 NAME Catalyst::Model::DBI - DBI Model Class =head1 SYNOPSIS # use the helper to create a model for example perl script/myapp_create.pl model MyModel DBI dsn username password # lib/MyApp/Model/DBI.pm package MyApp::Model::DBI; use base 'Catalyst::Model::DBI'; __PACKAGE__->config( dsn => 'DBI:Pg:dbname=mydb;host=localhost', username => 'pgsql', password => '', options => { AutoCommit => 1 }, loglevel => 1 ); 1; # or load settings from a config file via Config::General for example # in your myapp.conf you could have name MyApp dsn "DBI:Pg:dbname=mydb;host=localhost" username pgsql password "" AutoCommit 1 loglevel 1 # note that config settings always override Model settings # do something with $dbh inside a controller ... my $dbh = $c->model('MyModel')->dbh; # do something with $dbh inside a model ... my $dbh = $self->dbh; #do something with DBIx::Connector connection inside a controller ... my $connection = $c->model('MyModel')->connection; #do something with DBIx::Connector connection inside a model ... my $connection = $self->connection; =head1 DESCRIPTION This is the C model class. It has been rewritten to use L since it's internal code that deals with connection maintenance has already been ported into there. You now have two options for doing custom models with Catalyst. Either by using this model and any related modules as needed or by having your custom model decoupled from Catalyst and glued on using L Some general rules are as follows. If you do not wish to use L directly or DBI and setup connections in your custom models or have glue models, then use this model. If you however need models that can be re-used outside of your application or simply wish to maintain connection code yourself outside of the Catalyst, then use L which allows you to glue outside models into your Catalyst app. =head1 METHODS =over 4 =item new Initializes DBI connection =cut sub new { my $self = shift->next::method( @_ ); my ( $c, $config ) = @_; $self->{dsn} ||= $config->{dsn}; $self->{username} ||= $config->{username} || $config->{user}; $self->{password} ||= $config->{password} || $config->{pass}; $self->{options} ||= $config->{options}; $self->{namespace} ||= ref $self; $self->{additional_base_classes} ||= (); $self->{log} = $c->log; $self->{debug} = $c->debug; $self->{loglevel} ||= LOG_LEVEL_BASIC; return $self; } =item $self->connection Returns the current DBIx::Connector connection handle. =cut sub connection { return shift->connect( 0 ) ; } =item $self->dbh Returns the current database handle. =cut sub dbh { return shift->connect( 1 ); } =item $self->connect Connects to the database and returns the handle. =cut sub connect { my ( $self, $want_dbh ) = @_; my $connection = $self->_connection; my $dbh = $self->_dbh; my $log = $self->{log}; my $debug = $self->{debug}; my $loglevel = $self->{loglevel}; unless ( $connection ) { eval { $connection = DBIx::Connector->new( $self->{dsn}, $self->{username} || $self->{user}, $self->{password} || $self->{pass}, $self->{options} ); $dbh = $connection->dbh; $self->_dbh( $dbh ); $self->_connection( $connection ); }; if ($@) { $log->debug( qq/Couldn't connect to the database via DBIx::Connector "$@"/ ) if $debug && $loglevel >= LOG_LEVEL_BASIC; } else { $log->debug( 'Connected to the database using DBIx::Connector via dsn:' . $self->{dsn} ) if $debug && $loglevel >= LOG_LEVEL_BASIC; } } my $handle = $want_dbh ? $dbh : $connection; return $handle; } =back =head1 SEE ALSO L, L, L, L =head1 AUTHOR Alex Pavlovic, C =head1 COPYRIGHT Copyright (c) 2005 - 2012 the Catalyst::Model::DBI L as listed above. =head1 LICENSE This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Catalyst-Model-DBI-0.32/lib/Catalyst/Helper/Model/000755 000000 001751 00000000000 12141124764 021431 5ustar00rootalex000000 000000 Catalyst-Model-DBI-0.32/lib/Catalyst/Helper/Model/DBI.pm000644 001751 001751 00000003011 12141124537 022342 0ustar00alexalex000000 000000 package Catalyst::Helper::Model::DBI; use strict; use File::Spec; our $VERSION = '0.32'; =head1 NAME Catalyst::Helper::Model::DBI - Helper for DBI Models =head1 SYNOPSIS script/create.pl model DBI DBI dsn user password =head1 DESCRIPTION Helper for DBI Model. =head2 METHODS =over 4 =item mk_compclass Reads the database and makes a main model class =item mk_comptest Makes tests for the DBI Model. =back =cut sub mk_compclass { my ( $self, $helper, $dsn, $user, $pass ) = @_; $helper->{dsn} = $dsn || ''; $helper->{user} = $user || ''; $helper->{pass} = $pass || ''; my $file = $helper->{file}; $helper->render_file( 'dbiclass', $file ); return 1; } =head1 SEE ALSO L, L, L, L, L =head1 AUTHOR Alex Pavlovic, C =head1 LICENSE This library is free software . You can redistribute it and/or modify it under the same terms as perl itself. =cut 1; __DATA__ __dbiclass__ package [% class %]; use strict; use warnings; use parent 'Catalyst::Model::DBI'; __PACKAGE__->config( dsn => '[% dsn %]', user => '[% user %]', password => '[% pass %]', options => {}, ); =head1 NAME [% class %] - DBI Model Class =head1 SYNOPSIS See L<[% app %]> =head1 DESCRIPTION DBI Model Class. =head1 AUTHOR [% author %] =head1 LICENSE This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;