| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Starch::Store::DBIx::Connector; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | $Starch::Store::DBIx::Connector::VERSION = '0.03'; | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | Starch::Store::DBIx::Connector - Starch storage backend using DBIx::Connector. | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | my $starch = Starch->new( | 
| 12 |  |  |  |  |  |  | store => { | 
| 13 |  |  |  |  |  |  | class => '::DBIx::Connector', | 
| 14 |  |  |  |  |  |  | connector => [ | 
| 15 |  |  |  |  |  |  | $dsn, | 
| 16 |  |  |  |  |  |  | $username, | 
| 17 |  |  |  |  |  |  | $password, | 
| 18 |  |  |  |  |  |  | { RaiseError=>1, AutoCommit=>1 }, | 
| 19 |  |  |  |  |  |  | ], | 
| 20 |  |  |  |  |  |  | table => 'my_states', | 
| 21 |  |  |  |  |  |  | }, | 
| 22 |  |  |  |  |  |  | ); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | This L store uses L to set and get state data. | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | Very little is documented in this module as it is just a subclass | 
| 29 |  |  |  |  |  |  | of L modified to use L | 
| 30 |  |  |  |  |  |  | instead of L. | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =cut | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 1 |  |  | 1 |  | 13978 | use DBIx::Connector; | 
|  | 1 |  |  |  |  | 22737 |  | 
|  | 1 |  |  |  |  | 40 |  | 
| 35 | 1 |  |  | 1 |  | 9 | use Types::Standard -types; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 19 |  | 
| 36 | 1 |  |  | 1 |  | 4822 | use Scalar::Util qw( blessed ); | 
|  | 1 |  |  |  |  | 5 |  | 
|  | 1 |  |  |  |  | 57 |  | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 1 |  |  | 1 |  | 7 | use Moo; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 9 |  | 
| 39 | 1 |  |  | 1 |  | 496 | use strictures 2; | 
|  | 1 |  |  |  |  | 11 |  | 
|  | 1 |  |  |  |  | 46 |  | 
| 40 | 1 |  |  | 1 |  | 231 | use namespace::clean; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 12 |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | extends 'Starch::Store::DBI'; | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | after BUILD => sub{ | 
| 45 |  |  |  |  |  |  | my ($self) = @_; | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | # Get this loaded as early as possible. | 
| 48 |  |  |  |  |  |  | $self->connector(); | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | return; | 
| 51 |  |  |  |  |  |  | }; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | =head1 REQUIRED ARGUMENTS | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =head2 connector | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | This must be set to either an array ref arguments for L | 
| 58 |  |  |  |  |  |  | or a pre-built object (often retrieved using a method proxy). | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | When configuring Starch from static configuration files using a | 
| 61 |  |  |  |  |  |  | L | 
| 62 |  |  |  |  |  |  | is a good way to link your existing L object | 
| 63 |  |  |  |  |  |  | constructor in with Starch so that starch doesn't build its own. | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =cut | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | has '+_dbh_arg' => ( | 
| 69 |  |  |  |  |  |  | isa      => (InstanceOf[ 'DBIx::Connector' ]) | ArrayRef, | 
| 70 |  |  |  |  |  |  | init_arg => 'connector', | 
| 71 |  |  |  |  |  |  | reader   => '_connector_arg', | 
| 72 |  |  |  |  |  |  | ); | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | has '+dbh' => ( | 
| 75 |  |  |  |  |  |  | isa      => InstanceOf[ 'DBIx::Connector' ], | 
| 76 |  |  |  |  |  |  | init_arg => undef, | 
| 77 |  |  |  |  |  |  | reader   => 'connector', | 
| 78 |  |  |  |  |  |  | builder  => '_build_connector', | 
| 79 |  |  |  |  |  |  | ); | 
| 80 |  |  |  |  |  |  | sub _build_connector { | 
| 81 | 6 |  |  | 6 |  | 66 | my ($self) = @_; | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 6 |  |  |  |  | 20 | my $connector = $self->_connector_arg(); | 
| 84 | 6 | 50 |  |  |  | 34 | return $connector if blessed $connector; | 
| 85 |  |  |  |  |  |  |  | 
| 86 | 6 |  |  |  |  | 59 | return DBIx::Connector->new( @$connector ); | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head1 OPTIONAL ARGUMENTS | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head2 method | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | The L method to call when executing queries. | 
| 94 |  |  |  |  |  |  | Must be one of C, C, or C.  Defaults to C. | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =cut | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | has method => ( | 
| 99 |  |  |  |  |  |  | is      => 'ro', | 
| 100 |  |  |  |  |  |  | isa     => Enum['run', 'txn', 'svp'], | 
| 101 |  |  |  |  |  |  | default => 'run', | 
| 102 |  |  |  |  |  |  | ); | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =head2 mode | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | The L to use | 
| 107 |  |  |  |  |  |  | when running the L.  Defaults to C which lets | 
| 108 |  |  |  |  |  |  | L use whichever mode it has been configured to use. | 
| 109 |  |  |  |  |  |  | Must be on of C, C, C, or C. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | Typically you will not want to set this as you will have provided | 
| 112 |  |  |  |  |  |  | a pre-built L object, using a method proxy, which | 
| 113 |  |  |  |  |  |  | you've already called L on. | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =cut | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | has mode => ( | 
| 118 |  |  |  |  |  |  | is => 'ro', | 
| 119 |  |  |  |  |  |  | isa => (Enum['ping', 'fixup', 'no_ping']) | Undef, | 
| 120 |  |  |  |  |  |  | ); | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =head1 METHODS | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | =head2 set | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | Set L. | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =head2 get | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | Set L. | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =head2 remove | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | Set L. | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | =cut | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | # Little clean hack to make all of the DBI code "just work". | 
| 139 |  |  |  |  |  |  | # local() can be awesome. | 
| 140 |  |  |  |  |  |  | our $dbh; | 
| 141 | 57 |  |  | 57 | 1 | 18909 | sub dbh { $dbh } | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | around qw( set get remove ) => sub{ | 
| 144 |  |  |  |  |  |  | my ($orig, $self, @args) = @_; | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | local $Carp::Interal{ (__PACKAGE__) } = 1; | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | my $method = $self->method(); | 
| 149 |  |  |  |  |  |  | my $mode = $self->mode(); | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | return $self->connector->$method( | 
| 152 |  |  |  |  |  |  | defined($mode) ? ($mode) : (), | 
| 153 |  |  |  |  |  |  | sub{ | 
| 154 |  |  |  |  |  |  | local $dbh = $_; | 
| 155 |  |  |  |  |  |  | return $self->$orig( @args ); | 
| 156 |  |  |  |  |  |  | }, | 
| 157 |  |  |  |  |  |  | ); | 
| 158 |  |  |  |  |  |  | }; | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | 1; | 
| 161 |  |  |  |  |  |  | __END__ |