| 1 | package Fey::Loader; | ||||||||||
| 2 | { | ||||||||||
| 3 | 2 | $Fey::Loader::VERSION = '0.13'; | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use Fey::Loader::DBI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 12 | 3 | my $class = shift; | |||||||||
| 13 | 3 | my %p = @_; | |||||||||
| 14 | |||||||||||
| 15 | 3 | my $dbh = $p{dbh}; | |||||||||
| 16 | 3 | my $driver = $dbh->{Driver}{Name}; | |||||||||
| 17 | |||||||||||
| 18 | 3 | my $subclass = $class->_determine_subclass($driver); | |||||||||
| 19 | |||||||||||
| 20 | 3 | return $subclass->new(%p); | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 3 | ▶ | sub _determine_subclass { | ||||||||
|
Subroutine
_determine_subclass: called CC=4 SCAR=14.4
| |||||||||||
| 24 | 3 | my $class = shift; | |||||||||
| 25 | 3 | my $driver = shift; | |||||||||
| 26 | |||||||||||
| 27 | 3 | my $subclass = $class . '::' . $driver; | |||||||||
| 28 | |||||||||||
| 29 | { | ||||||||||
| 30 | |||||||||||
| 31 | # Shuts up UNIVERSAL::can | ||||||||||
| 32 | 2 | ▶ | no warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 3 | ▶ | return $subclass if $subclass->can('new'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | return $subclass if eval "use $subclass; 1;"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 3 | ▶ | die $@ unless $@ =~ /Can't locate/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | 3 | warn <<"EOF"; | |||||||||
| 41 | |||||||||||
| 42 | There is no driver-specific $class subclass for your driver ($driver) | ||||||||||
| 43 | ... falling back to the base DBI implementation. This may or may not | ||||||||||
| 44 | work. | ||||||||||
| 45 | |||||||||||
| 46 | EOF | ||||||||||
| 47 | |||||||||||
| 48 | 3 | return $class . '::' . 'DBI'; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 2 | 1; | |||||||||
| 52 | |||||||||||
| 53 | # ABSTRACT: Load your schema definition from a DBMS | ||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | |||||||||||
| 57 | =pod | ||||||||||
| 58 | |||||||||||
| 59 | =head1 NAME | ||||||||||
| 60 | |||||||||||
| 61 | Fey::Loader - Load your schema definition from a DBMS | ||||||||||
| 62 | |||||||||||
| 63 | =head1 VERSION | ||||||||||
| 64 | |||||||||||
| 65 | version 0.13 | ||||||||||
| 66 | |||||||||||
| 67 | =head1 SYNOPSIS | ||||||||||
| 68 | |||||||||||
| 69 | my $loader = Fey::Loader->new( dbh => $dbh ); | ||||||||||
| 70 | |||||||||||
| 71 | my $loader = Fey::Loader->new( | ||||||||||
| 72 | dbh => $dbh, | ||||||||||
| 73 | schema_class => '...', | ||||||||||
| 74 | table_class => '...', | ||||||||||
| 75 | ); | ||||||||||
| 76 | |||||||||||
| 77 | my $schema = $loader->make_schema(); | ||||||||||
| 78 | |||||||||||
| 79 | =head1 DESCRIPTION | ||||||||||
| 80 | |||||||||||
| 81 | C<Fey::Loader> takes a C<DBI> handle and uses it to construct a set of | ||||||||||
| 82 | Fey objects representing that schema. It will attempt to use an | ||||||||||
| 83 | appropriate DBMS subclass if one exists, but will fall back to using a | ||||||||||
| 84 | generic loader otherwise. | ||||||||||
| 85 | |||||||||||
| 86 | The generic loader simply uses the various schema information methods | ||||||||||
| 87 | specified by C<DBI>. This in turn depends on these methods being | ||||||||||
| 88 | implemented by the driver. | ||||||||||
| 89 | |||||||||||
| 90 | See the L<Fey::Loader::DBI> class for more details on what parameters the | ||||||||||
| 91 | C<new()> method accepts. | ||||||||||
| 92 | |||||||||||
| 93 | =head1 METHODS | ||||||||||
| 94 | |||||||||||
| 95 | This class provides the following methods: | ||||||||||
| 96 | |||||||||||
| 97 | =head2 Fey::Loader->new( dbh => $dbh ) | ||||||||||
| 98 | |||||||||||
| 99 | Given a connected C<DBI> handle, this method returns a new loader. If | ||||||||||
| 100 | an appropriate subclass exists, it will be loaded and used. Otherwise, | ||||||||||
| 101 | it will warn and fall back to using L<Fey::Loader::DBI>. | ||||||||||
| 102 | |||||||||||
| 103 | =head1 BUGS | ||||||||||
| 104 | |||||||||||
| 105 | Please report any bugs or feature requests to | ||||||||||
| 106 | C<bug-fey-loader@rt.cpan.org>, or through the web interface at | ||||||||||
| 107 | L<http://rt.cpan.org>. I will be notified, and then you'll | ||||||||||
| 108 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 109 | |||||||||||
| 110 | =head1 AUTHOR | ||||||||||
| 111 | |||||||||||
| 112 | Dave Rolsky <autarch@urth.org> | ||||||||||
| 113 | |||||||||||
| 114 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 115 | |||||||||||
| 116 | This software is Copyright (c) 2011 by Dave Rolsky. | ||||||||||
| 117 | |||||||||||
| 118 | This is free software, licensed under: | ||||||||||
| 119 | |||||||||||
| 120 | The Artistic License 2.0 (GPL Compatible) | ||||||||||
| 121 | |||||||||||
| 122 | =cut | ||||||||||
| 123 | |||||||||||
| 124 | |||||||||||
| 125 | __END__ | ||||||||||