| 1 | package Fey::Object::Schema; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 9 | $Fey::Object::Schema::VERSION = '0.46'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Fey::Meta::Class::Table; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub EnableObjectCaches { | ||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
EnableObjectCaches: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | $_->EnableObjectCache() for $class->_TableClasses(); | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub DisableObjectCaches { | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
DisableObjectCaches: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | $_->DisableObjectCache() for $class->_TableClasses(); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub ClearObjectCaches { | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
ClearObjectCaches: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | $_->ClearObjectCache() for $class->_TableClasses(); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub _TableClasses { | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_TableClasses: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my $schema = $class->Schema(); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | return Fey::Meta::Class::Table->ClassForTable( $schema->tables() ); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub RunInTransaction { | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
RunInTransaction: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my $sub = shift; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $source = shift || $class->DBIManager()->default_source(); | ||||||||||||||||||||||||||
|
Condition0%0/3
shift() || $class->DBIManager->default_source
MC/DC0%0/2
shift() || $class->DBIManager->default_source
shift()
$class->DBIManager->default_source
Truth table0%0/3
A || B
A= shift()B= $class->DBIManager->default_source
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $in_tran; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | my $dbh = $source->dbh(); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | unless ( $source->allows_nested_transactions() | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$source->allows_nested_transactions or $dbh->{"AutoCommit"}
MC/DC0%0/2
$source->allows_nested_transactions or $dbh->{"AutoCommit"}
$source->allows_nested_transactions
$dbh->{"AutoCommit"}
Truth table0%0/3
A or B
A= $source->allows_nested_transactionsB= $dbh->{"AutoCommit"}
| |||||||||||||||||||||||||||||
| 50 | || $dbh->{AutoCommit} ) { | ||||||||||||||||||||||||||||
| 51 | 0 | $in_tran = 1; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my $wantarray = wantarray; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | my @r; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | eval { | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | $dbh->begin_work() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | unless $in_tran; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 63 | 0 | @r = $sub->(); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | elsif ( defined $wantarray ) { | ||||||||||||||||||||||||||||
| 66 | 0 | $r[0] = $sub->(); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||
| 69 | 0 | $sub->(); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $dbh->commit() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | unless $in_tran; | ||||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( my $e = $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $dbh->rollback | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | unless $in_tran; | ||||||||||||||||||||||||||||
| 79 | 0 | die $e; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return unless defined $wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return $wantarray ? @r : $r[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | sub Schema { | ||||||||||||||||||||||||||||
| 88 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
Schema: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | return $class->meta()->schema(); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub DBIManager { | ||||||||||||||||||||||||||||
| 94 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
DBIManager: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 1 | return $class->meta()->dbi_manager(); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub SetDBIManager { | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
SetDBIManager: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | $class->meta()->set_dbi_manager(@_); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub SQLFactoryClass { | ||||||||||||||||||||||||||||
| 106 | 10 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
SQLFactoryClass: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 10 | return $class->meta()->sql_factory_class(); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub SetSQLFactoryClass { | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
SetSQLFactoryClass: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | $class->meta()->set_sql_factory_class(@_); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 9 | __PACKAGE__->meta()->make_immutable( inline_constructor => 0 ); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 9 | 1; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # ABSTRACT: Base class for schema-based objects | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =pod | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head1 NAME | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Fey::Object::Schema - Base class for schema-based objects | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head1 VERSION | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | version 0.46 | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | package MyApp::Schema; | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | use Fey::ORM::Schema; | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | has_schema(...); | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | This class is a the base class for all schema-based objects. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head1 METHODS | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | This class provides the following methods: | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head2 $class->EnableObjectCaches() | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | Enables the object class for all of the table classes associated with | ||||||||||||||||||||||||||||
| 154 | this class's schema. | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =head2 $class->DisableObjectCaches() | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | Disables the object class for all of the table classes associated with | ||||||||||||||||||||||||||||
| 159 | this class's schema. | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head2 $class->ClearObjectCaches() | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Clears the object class for all of the table classes associated with | ||||||||||||||||||||||||||||
| 164 | this class's schema. | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head2 $class->RunInTransaction( $coderef, $source ) | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | Given a code ref, this method will begin a transaction and execute the | ||||||||||||||||||||||||||||
| 169 | coderef. If the coderef runs normally (no exceptions), it commits, | ||||||||||||||||||||||||||||
| 170 | otherwise it rolls back and rethrows the error. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | This method will handle nested transactions gracefully if your | ||||||||||||||||||||||||||||
| 173 | DBMS does not. It doesn't emulate actual partial commits, but it | ||||||||||||||||||||||||||||
| 174 | does prevent DBI from throwing an error. | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | The second argument can be a L<Fey::DBIManager::Source> object. If no | ||||||||||||||||||||||||||||
| 177 | source is specified, then this method will use the default source. | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head2 $class->Schema() | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Returns the L<Fey::Schema> object associated with the class. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =head2 $class->DBIManager() | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | Returns the L<Fey::Schema> object associated with the class. | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =head2 $class->SetDBIManager($manager) | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | Set the L<Fey::DBIManager> object associated with the class. If you | ||||||||||||||||||||||||||||
| 190 | don't set one explicitly, then the first call to C<< | ||||||||||||||||||||||||||||
| 191 | $class->DBIManager() >> will simply create one by calling C<< | ||||||||||||||||||||||||||||
| 192 | Fey::DBIManager->new() >>. | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =head2 $class->SQLFactoryClass() | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | Returns the SQL factory class associated with the class. This defaults | ||||||||||||||||||||||||||||
| 197 | to L<Fey::SQL>. | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head2 $class->SetSQLFactoryClass() | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | Set the SQL factory class associated with the class. | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | Dave Rolsky <autarch@urth.org> | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | This software is copyright (c) 2011 by Dave Rolsky. | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 212 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||||||||||