| 1 | package SPOPS::Key::Random; | ||
| 2 | |||
| 3 | # $Id: Random.pm,v 3.4 2004/06/02 00:48:23 lachoy Exp $ | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use Log::Log4perl qw( get_logger ); | ||
| 7 | use SPOPS; | ||
| 8 | use SPOPS::Utility; | ||
| 9 | |||
| 10 | $SPOPS::Key::Random::VERSION = sprintf("%d.%02d", q$Revision: 3.4 $ =~ /(\d+)\.(\d+)/); | ||
| 11 | |||
| 12 | use constant DEFAULT_ID_WIDTH => 8; | ||
| 13 | |||
| 14 | my $log = get_logger(); | ||
| 15 | |||
| 16 | sub pre_fetch_id { | ||
| 17 | my ( $class, $p ) = @_; | ||
| 18 | my $width = $p->{id_width}; | ||
| 19 | unless ( $width ) { | ||
| 20 | my $config = eval { $class->CONFIG }; | ||
| 21 | if ( ref $config ) { | ||
| 22 | $width = $class->CONFIG->{id_width}; | ||
| 23 | } | ||
| 24 | $width ||= DEFAULT_ID_WIDTH; | ||
| 25 | } | ||
| 26 | my $code = SPOPS::Utility->generate_random_code( $width ); | ||
| 27 | $log->warn( "Created insert ID [$code]" ); | ||
| 28 | return ( $code, 1 ); | ||
| 29 | } | ||
| 30 | |||
| 31 | sub post_fetch_id { return undef } | ||
| 32 | |||
| 33 | 1; | ||
| 34 | |||
| 35 | __END__ |