File Coverage

lib/Workflow/Persister/RandomId.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition 2 2 100.0
subroutine 9 9 100.0
pod 3 3 100.0
total 41 41 100.0


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