File Coverage

lib/Workflow/Persister/DBI/SequenceId.pm
Criterion Covered Total %
statement 25 38 65.7
branch 0 2 0.0
condition 1 2 50.0
subroutine 8 10 80.0
pod 3 3 100.0
total 37 55 67.2


line stmt bran cond sub pod time code
1              
2             use warnings;
3 13     13   117 use strict;
  13         22  
  13         427  
4 13     13   70 use base qw( Class::Accessor );
  13         33  
  13         330  
5 13     13   72 use DBI;
  13         26  
  13         1211  
6 13     13   109 use Log::Log4perl qw( get_logger );
  13         23  
  13         500  
7 13     13   83 use Workflow::Exception qw( persist_error );
  13         31  
  13         104  
8 13     13   733 use English qw( -no_match_vars );
  13         43  
  13         593  
9 13     13   73  
  13         30  
  13         101  
10             $Workflow::Persister::DBI::SequenceId::VERSION = '1.60';
11              
12             my @FIELDS = qw( log sequence_name sequence_select );
13             __PACKAGE__->mk_accessors(@FIELDS);
14              
15              
16             my ( $class, $params ) = @_;
17             $params ||= {};
18 2     2 1 4 $params->{log} = get_logger( $class );
19 2   50     6  
20 2         5 return bless { %$params }, $class;
21             }
22 2         434  
23             my ( $self, $dbh ) = @_;
24             my $full_select = sprintf $self->sequence_select, $self->sequence_name;
25             $self->log->debug("SQL to fetch sequence: ", $full_select);
26 0     0 1   my ($row);
27 0           eval {
28 0           my $sth = $dbh->prepare($full_select);
29 0           $sth->execute;
30 0           $row = $sth->fetchrow_arrayref;
31 0           $sth->finish;
32 0           };
33 0           if ($EVAL_ERROR) {
34 0           persist_error "Failed to retrieve sequence: $EVAL_ERROR";
35             }
36 0 0         return $row->[0];
37 0           }
38              
39 0            
40             1;
41              
42 0     0 1    
43             =pod
44              
45             =head1 NAME
46              
47             Workflow::Persister::DBI::SequenceId - Persister to fetch ID from a sequence
48              
49             =head1 VERSION
50              
51             This documentation describes version 1.60 of this package
52              
53             =head1 SYNOPSIS
54              
55             <persister
56             name="MyPersister"
57             workflow_sequence="wf_seq"
58             history_sequence="wf_history_seq"
59             ...
60              
61             =head1 DESCRIPTION
62              
63             Implementation for DBI persister to fetch an ID value from a sequence.
64              
65             =head2 Properties
66              
67             B<sequence_name>
68              
69             Name of the sequence to select the next id value from.
70              
71             B<sequence_select>
72              
73             C<sprintf> template string with a single placeholder (C<%s>) used to
74             interpolate the sequence name. The resulting string is used as the SQL
75             statement to retrieve the next sequence value.
76              
77             =head2 ATTRIBUTES
78              
79             =head3 log
80              
81             Contains the logger object associated with this instance.
82              
83             =head2 METHODS
84              
85             =head3 new ( \%params )
86              
87             This method instantiates a class for retrieval of sequence ids from a
88             L<DBI> based persistance entity.
89              
90             It takes a hashref containing keys matching the properties outlines in the
91             section above or throws L<Workflow::Exception>s if these are not defined.
92              
93             Returns instantiated object upon success.
94              
95             =head3 pre_fetch_id
96              
97             Returns a unique sequence id from a database.
98              
99             Takes a single parameter, a L<DBI> database handle.
100              
101             Returns a single value, a integer representing a sequence id from the provided
102             database handle.
103              
104             =head3 post_fetch_id
105              
106             This is a I<dummy> method, use L</pre_fetch_id>
107              
108             =head1 COPYRIGHT
109              
110             Copyright (c) 2003-2022 Chris Winters. All rights reserved.
111              
112             This library is free software; you can redistribute it and/or modify
113             it under the same terms as Perl itself.
114              
115             Please see the F<LICENSE>
116              
117             =head1 AUTHORS
118              
119             Please see L<Workflow>
120              
121             =cut