| 1 | package Class::DBI::SAK; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use vars qw[$VERSION %EXTENSIONS @OVERRIDES]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | # use warnings; | ||||||||||
| 7 | |||||||||||
| 8 | 1 | $VERSION = '1.4'; | |||||||||
| 9 | |||||||||||
| 10 | 1 | %EXTENSIONS = ( | |||||||||
| 11 | ':useful' => { | ||||||||||
| 12 | 'AbstractSearch' => 'use %s', | ||||||||||
| 13 | 'Pager' => 'use %s', | ||||||||||
| 14 | }, | ||||||||||
| 15 | ':mysql' => { | ||||||||||
| 16 | 'mysql' => 'use base qw[%s]', | ||||||||||
| 17 | 'mysql::FullTextSearch' => 'use %s', | ||||||||||
| 18 | }, | ||||||||||
| 19 | 'Extension' => 'use base qw[%s]', | ||||||||||
| 20 | 'FromCGI' => 'use %s', | ||||||||||
| 21 | 'Pg' => 'use base qw[%s]', | ||||||||||
| 22 | 'Replication' => 'use base qw[%s]', | ||||||||||
| 23 | 'SQLite' => 'use base qw[%s]', | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | $EXTENSIONS{':all'} = { map { | ||||||||||
| 27 | 1 | ref $EXTENSIONS{$_} ? | |||||||||
| 28 | 2 | %{$EXTENSIONS{$_}} : | |||||||||
| 29 | 7 | ▶ | ( $_ => $EXTENSIONS{$_} ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | } keys %EXTENSIONS }; | ||||||||||
| 31 | |||||||||||
| 32 | 1 | @OVERRIDES = ( qw[ | |||||||||
| 33 | Extension mysql Pg Replication SQLite | ||||||||||
| 34 | ] ); | ||||||||||
| 35 | |||||||||||
| 36 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=10 SCAR=24.2
| |||||||||||
| 37 | 1 | my ($class, @requests) = @_; | |||||||||
| 38 | 1 | my $caller = caller(0); | |||||||||
| 39 | 1 | my %modules = (); | |||||||||
| 40 | 1 | my @uses = (); | |||||||||
| 41 | |||||||||||
| 42 | 1 | ▶ | @requests = ':useful' unless @requests; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 1 | foreach my $req ( @requests ) { | |||||||||
| 45 | 1 | ▶ | if ( substr( $req, 0, 1 ) eq ':' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 1 | ▶ | if ( exists $EXTENSIONS{$req} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | $modules{$_} = $EXTENSIONS{$req}->{$_} | ||||||||||
| 48 | 1 | foreach keys %{$EXTENSIONS{$req}}; | |||||||||
| 49 | } else { | ||||||||||
| 50 | 0 | croak "$class does not export a $req tag"; | |||||||||
| 51 | } | ||||||||||
| 52 | } else { | ||||||||||
| 53 | 0 | ▶ | if ( exists $EXTENSIONS{':all'}->{$req} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | $modules{$req} = $EXTENSIONS{':all'}->{$req}; | |||||||||
| 55 | } else { | ||||||||||
| 56 | 0 | croak "$class does not export $req\n"; | |||||||||
| 57 | } | ||||||||||
| 58 | } | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 1 | ▶ | while ( my ($name, $use) = each %modules ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 2 | push @uses, sprintf $use, "Class::DBI::$name"; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | unshift @uses, 'use base qw[Class::DBI]' | ||||||||||
| 66 | 1 | ▶ | unless grep { exists $modules{$_} } @OVERRIDES; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | |||||||||||
| 68 | 1 | @uses = sort { ( () = $b =~ /base/ ) <=> ( () = $a =~ /base/ ) } @uses; | |||||||||
| 69 | |||||||||||
| 70 | my $statement = join ";\n", sort { | ||||||||||
| 71 | 1 | ( () = $b =~ /base/ ) <=> ( () = $a =~ /base/ ) | |||||||||
| 72 | } @uses; | ||||||||||
| 73 | 1 | $statement .= ";\n"; | |||||||||
| 74 | |||||||||||
| 75 | 1 | ▶ | eval qq[ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 76 | package $caller; | ||||||||||
| 77 | $statement; | ||||||||||
| 78 | package $class; | ||||||||||
| 79 | ]; | ||||||||||
| 80 | 1 | ▶ | croak $@ if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 1 | 1; | |||||||||
| 84 | |||||||||||
| 85 | __END__ | ||||||||||