SQLEngine/Driver/Trait/DatabaseFlavors.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 51 CC 2 SCAR 10.0
CC
2
Cov
0%
select_dbms_flavor
6.0
import
2.0
_init
2.0
CRAP 2.7
1 =head1 NAME
2  
3 DBIx::SQLEngine::Driver::Trait::DatabaseFlavors - For minor variations in a database
4  
5 =head1 SYNOPSIS
6  
7 # Classes can import this behavior if they have further subclasses
8 use DBIx::SQLEngine::Driver::Trait::DatabaseFlavors ':all';
9
10  
11  
12 =head1 DESCRIPTION
13  
14 This package supports configurations of drivers or database servers which differ from the generic implementation provided by their driver.
15  
16 =head2 Variations Within a Driver Class
17  
18 Beyond the fundamental subclassing based on driver type lies a more subtle range of variations.
19  
20 How do we compensate for different versions of a database system? For example, newer versions of MySQL support a number of features that the old ones don't: transactions were added in 3.23 (for some table types); union selects were added in 4.0; and stored procedures are being added in 5.0. Similarly DBD::SQLite's functionality is limited by the version of the SQLite C library is in use, and DBD::AnyData's level of functionality depends on which version of SQL::Statement is installed.
21  
22 Similarly, how do we detect driver/server combinations that need extra help? For example, placeholders will fail for Linux users of DBD::Sybase connecting to MS SQL Servers on Windows, so they need a special subclass which uses the NoPlaceholders trait.
23  
24 This is handled by the "dbms_flavor" interface. When a flavor is selected, detected, or defaulted, the driver in question is reblessed into an appropriate subclass, such as Driver::MySQL::3_23, Driver::MySQL::5_0, or Driver::Sybase::MSSQL.
25  
26 =head2 About Driver Traits
27  
28 You do not need to use this package directly; it is used internally by those driver subclasses which need it.
29  
30 For more information about Driver Traits, see L<DBIx::SQLEngine::Driver/"About Driver Traits">.
31  
32 =cut
33  
34 ########################################################################
35  
36 package DBIx::SQLEngine::Driver::Trait::DatabaseFlavors;
37  
38 use Exporter;
39 sub import { goto &Exporter::import }
40 @EXPORT_OK = qw(
41 _init
42 default_dbms_flavor detect_dbms_flavor
43 select_dbms_flavor select_default_dbms_flavor select_detect_dbms_flavor
44 );
45 %EXPORT_TAGS = ( all => \@EXPORT_OK );
46  
47 use strict;
48 use Carp;
49  
50 ########################################################################
51  
52 ########################################################################
53  
54 =head1 INTERNAL CONNECTION METHODS (DBI DBH)
55  
56 =head2 Initialization and Reconnection
57  
58 =over 4
59  
60 =item _init()
61  
62 $sqldb->_init ()
63  
64 Calls select_default_dbms_flavor().
65  
66 Internal method, called by DBIx::AnyDBD after connection is made and class hierarchy has been juggled.
67  
68 =back
69  
70 =cut
71  
72 sub _init {
73 (shift)->select_default_dbms_flavor()
74 }
75  
76 ########################################################################
77  
78 =head1 DRIVER AND DATABASE FLAVORS
79  
80 =head2 Detecting DBMS Flavors
81  
82 =over 4
83  
84 =item default_dbms_flavor()
85  
86 $sqldb->default_dbms_flavor() : $flavor_name
87  
88 Subclass hook. Default returns empty string, to not select any flavor.
89  
90 =item detect_dbms_flavor()
91  
92 $sqldb->detect_dbms_flavor() : $flavor_name
93  
94 Subclass hook. Default returns empty string, to not select any flavor.
95  
96 =back
97  
98 =cut
99  
100 sub default_dbms_flavor { '' }
101  
102 sub detect_dbms_flavor { '' }
103  
104 ########################################################################
105  
106 =head2 Applying DBMS Flavors
107  
108 =over 4
109  
110 =item select_dbms_flavor()
111  
112 $sqldb->select_dbms_flavor( $flavor_name )
113  
114 Reblesses the driver to a subclass based on the flavor name.
115  
116 =item select_default_dbms_flavor()
117  
118 $sqldb->select_default_dbms_flavor( )
119  
120 Calls select_dbms_flavor() with the result of default_dbms_flavor().
121  
122 =item select_detect_dbms_flavor()
123  
124 $sqldb->select_detect_dbms_flavor( )
125  
126 Calls select_dbms_flavor() with the result of detect_dbms_flavor() or default_dbms_flavor().
127  
128 =back
129  
130 =cut
131  
132 sub select_dbms_flavor {
133 my ($self, $flavor) = @_;
134 my $class = ref( $self ) or croak("This is not a class method");
135 # warn "Reblessing object of class '$class'\n";
136 $class =~ s/(Driver::\w+)::.*$/$1/;
137 my $flavor_class = $class . ( $flavor ? "::$flavor" : '' );
138 # warn " ... new class is '$flavor_class'\n";
139 bless $self, $flavor_class;
140 }
141  
142 sub select_default_dbms_flavor {
143 my $self = shift;
144 $self->select_dbms_flavor( $self->default_dbms_flavor() );
145 }
146  
147 sub select_detect_dbms_flavor {
148 my $self = shift;
149 $self->select_dbms_flavor( $self->detect_dbms_flavor() or
150 $self->default_dbms_flavor() )
151 }
152  
153 ########################################################################
154  
155 =head1 SEE ALSO
156  
157 See L<DBIx::SQLEngine> for the overall interface and developer documentation.
158  
159 See L<DBIx::SQLEngine::Docs::ReadMe> for general information about
160 this distribution, including installation and license information.
161  
162 =cut
163  
164 ########################################################################
165  
166 1;