File Coverage

blib/lib/Workflow/Persister/RandomId.pm
Criterion Covered Total %
statement 29 29 100.0
branch n/a
condition 2 2 100.0
subroutine 10 10 100.0
pod 3 3 100.0
total 44 44 100.0


line stmt bran cond sub pod time code
1             package Workflow::Persister::RandomId;
2              
3 27     27   1297285 use warnings;
  27         111  
  27         2308  
4 27     27   173 use strict;
  27         69  
  27         791  
5 27     27   408 use v5.14.0;
  27         104  
6 27     27   198 use parent qw( Class::Accessor );
  27         57  
  27         215  
7              
8 27     27   7417 use constant DEFAULT_ID_LENGTH => 8;
  27         55  
  27         2361  
9 27     27   159 use constant RANDOM_SEED => 26;
  27         83  
  27         1408  
10 27     27   156 use constant CONSTANT_INCREMENT => 65;
  27         55  
  27         9587  
11              
12             $Workflow::Persister::RandomId::VERSION = '2.09';
13              
14             my @FIELDS = qw( id_length );
15             __PACKAGE__->mk_accessors(@FIELDS);
16              
17             sub new {
18 28     28 1 2131 my ( $class, $params ) = @_;
19 28         93 my $self = bless {}, $class;
20 28   100     141 my $length = $params->{id_length} || DEFAULT_ID_LENGTH;
21 28         145 $self->id_length($length);
22 28         653 return $self;
23             }
24              
25             sub pre_fetch_id {
26 77     77 1 3719 my ( $self, $dbh ) = @_;
27             return join '',
28 77         371 map { chr int( rand RANDOM_SEED ) + CONSTANT_INCREMENT }
  644         3769  
29             ( 1 .. $self->id_length );
30             }
31              
32 1     1 1 703 sub post_fetch_id {return}
33              
34             1;
35              
36             __END__
37              
38             =pod
39              
40             =head1 NAME
41              
42             Workflow::Persister::RandomId - Persister to generate random ID
43              
44             =head1 VERSION
45              
46             This documentation describes version 2.09 of this package
47              
48             =head1 SYNOPSIS
49              
50             persister:
51             - name: MyPersister
52             id_length: 16
53             ...
54              
55             =head1 DESCRIPTION
56              
57             Implementation for any persister to generate a random ID string. You
58             can specify the length using the 'id_length' parameter, but normally
59             the default (8 characters) is sufficient.
60              
61             =head2 METHODS
62              
63             =head3 new
64              
65             Instantiates a Workflow::Persister::RandomId object, this object can generate
66             randon Id's based on the 'id_length' parameter provided. This parameter defaults
67             to 8.
68              
69             =head3 pre_fetch_id
70              
71             L</pre_fetch_id> can then be used to generate/retrieve a random ID, generated
72             adhering to the length specified in the constructor call.
73              
74             =head3 post_fetch_id
75              
76             This method is unimplemented at this time, please see the TODO.
77              
78             =head1 TODO
79              
80             =over
81              
82             =item * Implement L</post_fetch_id>
83              
84             =back
85              
86             =head1 COPYRIGHT
87              
88             Copyright (c) 2003-2021 Chris Winters. All rights reserved.
89              
90             This library is free software; you can redistribute it and/or modify
91             it under the same terms as Perl itself.
92              
93             Please see the F<LICENSE>
94              
95             =head1 AUTHORS
96              
97             Please see L<Workflow>
98              
99             =cut