Workflow::Persister::RandomId - Persister to generate random ID


Workflow documentation Contained in the Workflow distribution.

Index


Code Index:

NAME

Top

Workflow::Persister::RandomId - Persister to generate random ID

VERSION

Top

This documentation describes version 1.03 of this package

SYNOPSIS

Top

 <persister
     name="MyPersister"
     id_length="16"
 ...

DESCRIPTION

Top

Implementation for any persister to generate a random ID string. You can specify the length using the 'id_length' parameter, but normally the default (8 characters) is sufficient.

METHODS

new

Instantiates a Workflow::Persister::RandomId object, this object can generate randon Id's based on the 'id_length' parameter provided. This parameter defaults to 8.

pre_fetch_id

pre_fetch_id can then be used to generate/retrieve a random ID, generated adhering to the length specified in the constructor call.

post_fetch_id

This method is unimplemented at this time, please see the TODO.

TODO

Top

* Implement post_fetch_id

COPYRIGHT

Top

AUTHORS

Top

Chris Winters <chris@cwinters.com>


Workflow documentation Contained in the Workflow distribution.

package Workflow::Persister::RandomId;

# $Id: RandomId.pm 454 2009-01-12 10:04:02Z jonasbn $

use warnings;
use strict;
use base qw( Class::Accessor );

use constant DEFAULT_ID_LENGTH  => 8;
use constant RANDOM_SEED        => 26;
use constant CONSTANT_INCREMENT => 65;

$Workflow::Persister::RandomId::VERSION = '1.03';

my @FIELDS = qw( id_length );
__PACKAGE__->mk_accessors(@FIELDS);

sub new {
    my ( $class, $params ) = @_;
    my $self = bless {}, $class;
    my $length = $params->{id_length} || DEFAULT_ID_LENGTH;
    $self->id_length($length);
    return $self;
}

sub pre_fetch_id {
    my ( $self, $dbh ) = @_;
    return join '',
        map { chr int( rand RANDOM_SEED ) + CONSTANT_INCREMENT }
        ( 1 .. $self->id_length );
}

sub post_fetch_id {return}

1;

__END__