| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 1 |  |  | 1 |  | 1013 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 2 | 1 |  |  | 1 |  | 3 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | package Footprintless::Plugin::Database; | 
| 5 |  |  |  |  |  |  | $Footprintless::Plugin::Database::VERSION = '1.00'; | 
| 6 |  |  |  |  |  |  | # ABSTRACT: A Footprintless plugin for working with databases | 
| 7 |  |  |  |  |  |  | # PODNAME: Footprintless::Plugin::Database | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 3 | use Footprintless::Util qw(dynamic_module_new); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 1 |  |  | 1 |  | 3 | use parent qw(Footprintless::Plugin); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub db { | 
| 14 | 8 |  |  | 8 | 1 | 15 | my ( $self, $footprintless, $coordinate, @rest ) = @_; | 
| 15 | 8 | 50 |  |  |  | 20 | die("database plugin config required") unless ( $self->{config} ); | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 8 |  |  |  |  | 20 | my $entity = $footprintless->entities()->get_entity($coordinate); | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | my $provider = | 
| 20 |  |  |  |  |  |  | $entity->{provider} ? $self->{config}{providers}{ $entity->{provider} } | 
| 21 |  |  |  |  |  |  | : $self->{config}{default_provider} | 
| 22 |  |  |  |  |  |  | ? $self->{config}{providers}{ $self->{config}{default_provider} } | 
| 23 | 8 | 50 |  |  |  | 117 | : undef; | 
|  |  | 100 |  |  |  |  |  | 
| 24 | 8 | 100 |  |  |  | 27 | if ($provider) { | 
| 25 | 7 |  |  |  |  | 20 | return dynamic_module_new( $provider, $footprintless, $coordinate, @rest ); | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  | else { | 
| 28 | 1 | 50 |  |  |  | 3 | if ( $entity->{provider} ) { | 
| 29 | 1 |  |  |  |  | 11 | die("unsupported database provider: $entity->{provider}"); | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  | else { | 
| 32 | 0 |  |  |  |  | 0 | die("provider not specified and no default configured"); | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub db_command_helper { | 
| 38 | 0 |  |  | 0 | 1 | 0 | my ( $self, $footprintless, $coordinate, @rest ) = @_; | 
| 39 |  |  |  |  |  |  | return $self->{config}{command_helper} | 
| 40 |  |  |  |  |  |  | ? dynamic_module_new( $self->{config}{command_helper} ) | 
| 41 | 0 | 0 |  |  |  | 0 | : dynamic_module_new('Footprintless::Plugin::Database::DefaultCommandHelper'); | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | sub factory_methods { | 
| 45 | 8 |  |  | 8 | 1 | 20142 | my ($self) = @_; | 
| 46 |  |  |  |  |  |  | return { | 
| 47 |  |  |  |  |  |  | db => sub { | 
| 48 | 8 |  |  | 8 |  | 61 | return $self->db(@_); | 
| 49 |  |  |  |  |  |  | }, | 
| 50 |  |  |  |  |  |  | db_command_helper => sub { | 
| 51 | 0 |  |  | 0 |  |  | return $self->db_command_helper(@_); | 
| 52 |  |  |  |  |  |  | } | 
| 53 | 8 |  |  |  |  | 57 | }; | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | 1; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | __END__ |