/usr/share/perl5/Class/DBI/Loader.pm is in libclass-dbi-loader-perl 0.34-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | package Class::DBI::Loader;
use strict;
use vars '$VERSION';
$VERSION = '0.34';
=head1 NAME
Class::DBI::Loader - Dynamic definition of Class::DBI sub classes.
=head1 SYNOPSIS
use Class::DBI::Loader;
my $loader = Class::DBI::Loader->new(
dsn => "dbi:mysql:dbname",
user => "root",
password => "",
options => { RaiseError => 1, AutoCommit => 0 },
namespace => "Data",
additional_classes => qw/Class::DBI::AbstractSearch/, # or arrayref
additional_base_classes => qw/My::Stuff/, # or arrayref
left_base_classes => qw/Class::DBI::Sweet/, # or arrayref
constraint => '^foo.*',
relationships => 1,
options => { AutoCommit => 1 },
inflect => { child => 'children' },
require => 1
);
my $class = $loader->find_class('film'); # $class => Data::Film
my $obj = $class->retrieve(1);
use with mod_perl
in your startup.pl
# load all tables
use Class::DBI::Loader;
my $loader = Class::DBI::Loader->new(
dsn => "dbi:mysql:dbname",
user => "root",
password => "",
namespace => "Data",
);
in your web application.
use strict;
# you can use Data::Film directly
my $film = Data::Film->retrieve($id);
=head1 DESCRIPTION
Class::DBI::Loader automate the definition of Class::DBI sub-classes.
scan table schemas and setup columns, primary key.
class names are defined by table names and namespace option.
+-----------+-----------+-----------+
| table | namespace | class |
+-----------+-----------+-----------+
| foo | Data | Data::Foo |
| foo_bar | | FooBar |
+-----------+-----------+-----------+
Class::DBI::Loader supports MySQL, Postgres and SQLite.
See L<Class::DBI::Loader::Generic>.
=cut
sub new {
my ( $class, %args ) = @_;
my $dsn = $args{dsn};
my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
$driver = 'SQLite' if $driver eq 'SQLite2';
my $impl = "Class::DBI::Loader::" . $driver;
eval qq/use $impl/;
die qq/Couldn't require loader class "$impl", "$@"/ if $@;
return $impl->new(%args);
}
=head1 METHODS
=head2 new %args
=over 4
=item additional_base_classes
List of additional base classes your table classes will use.
=item left_base_classes
List of additional base classes, that need to be leftmost, for
example L<Class::DBI::Sweet> (former L<Catalyst::Model::CDBI::Sweet>).
=item additional_classes
List of additional classes which your table classes will use.
=item constraint
Only load tables matching regex.
=item exclude
Exclude tables matching regex.
=item debug
Enable debug messages.
=item dsn
DBI Data Source Name.
=item namespace
Namespace under which your table classes will be initialized.
=item password
Password.
=item options
Optional hashref to specify DBI connect options
=item relationships
Try to automatically detect/setup has_a and has_many relationships.
=item inflect
An hashref, which contains exceptions to Lingua::EN::Inflect::PL().
Useful for foreign language column names.
=item user
Username.
=item require
Attempt to require the dynamically defined module, so that extensions
defined in files. By default errors from imported modules are suppressed.
When you want to debug, use require_warn.
=item require_warn
Warn of import errors when requiring modules.
=back
=head1 AUTHOR
Daisuke Maki C<dmaki@cpan.org>
=head1 AUTHOR EMERITUS
Sebastian Riedel, C<sri@oook.de>
IKEBE Tomohiro, C<ikebe@edge.co.jp>
=head1 THANK YOU
Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
Randal Schwartz, Simon Flack and all the others who've helped.
=head1 LICENSE
This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=head1 SEE ALSO
L<Class::DBI>, L<Class::DBI::mysql>, L<Class::DBI::Pg>, L<Class::DBI::SQLite>,
L<Class::DBI::Loader::Generic>, L<Class::DBI::Loader::mysql>,
L<Class::DBI::Loader::Pg>, L<Class::DBI::Loader::SQLite>
=cut
1;
|