pax_global_header00006660000000000000000000000064125656112130014514gustar00rootroot0000000000000052 comment=60a10965d0dbe6a392c0b09b5e6ef8f5ceda3448 libdata-uniqid-perl-0.12/000077500000000000000000000000001256561121300152655ustar00rootroot00000000000000libdata-uniqid-perl-0.12/Changes000066400000000000000000000002371256561121300165620ustar00rootroot00000000000000Revision history for Perl extension Data::Uniqid. 0.01 Sun Jun 1 12:31:57 2003 - original version; created by h2xs 1.21 with options -X -n Data::Uniqid libdata-uniqid-perl-0.12/MANIFEST000066400000000000000000000000661256561121300164200ustar00rootroot00000000000000Changes Makefile.PL MANIFEST README test.pl Uniqid.pm libdata-uniqid-perl-0.12/Makefile.PL000066400000000000000000000011341256561121300172360ustar00rootroot00000000000000use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Data::Uniqid', 'VERSION_FROM' => 'Uniqid.pm', # finds $VERSION 'PREREQ_PM' => { Math::BigInt => 0, Time::HiRes => 0, Sys::Hostname => 0 }, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'Uniqid.pm', # retrieve abstract from module AUTHOR => 'A. U. Thor ') : ()), ); libdata-uniqid-perl-0.12/README000066400000000000000000000011311256561121300161410ustar00rootroot00000000000000Data/Uniqid Readme Data::Uniqid provides three simple routines for generating unique ids. These ids are coded with a Base62 systen to make them short and handy (e.g. to use it as part of a URL). INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Math::BigInt Sys::Hostname Time::HiRes COPYRIGHT AND LICENCE Copyright (C) 2003 Mike Wesemann This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. libdata-uniqid-perl-0.12/Uniqid.pm000066400000000000000000000042611256561121300170570ustar00rootroot00000000000000package Data::Uniqid; use 5.006; use strict; use warnings; require Exporter; use AutoLoader qw(AUTOLOAD); our @ISA = qw(Exporter); our %EXPORT_TAGS = ( 'all' => [ qw( suniqid uniqid luniqid ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '0.12'; use Math::BigInt; use Sys::Hostname; use Time::HiRes qw( gettimeofday usleep ); sub base62() { ################################################### Base62 ##### my($s)=@_; my(@c)=('0'..'9','a'..'z','A'..'Z'); my(@p,$u,$v,$i,$n); my($m)=20; $p[0]=1; for $i (1..$m) { $p[$i]=Math::BigInt->new($p[$i-1]); $p[$i]=$p[$i]->bmul(62); } $v=Math::BigInt->new($s); for ($i=$m;$i>=0;$i--) { $v=Math::BigInt->new($v); ($n,$v)=$v->bdiv($p[$i]); $u.=$c[$n]; } $u=~s/^0+//; return($u); } sub suniqid { ########################################### get unique id ##### my($s,$us)=gettimeofday();usleep(1); my($v)=sprintf("%06d%05d%06d",$us,substr($s,-5),$$); return(&base62($v)); } sub uniqid { ########################################### get unique id ##### my($s,$us)=gettimeofday();usleep(1); my($v)=sprintf("%06d%010d%06d",$us,$s,$$); return(&base62($v)); } sub luniqid { ############################################ get unique id ##### my($s,$us)=gettimeofday();usleep(1); my($ia,$ib,$ic,$id)=unpack("C4", (gethostbyname(hostname()))[4]); my($v)=sprintf("%06d%10d%06d%03d%03d%03d%03d",$us,$s,$$,$ia,$ib,$ic,$id); return(&base62($v)); } 1; __END__ =head1 NAME Data::Uniqid - Perl extension for simple genrating of unique id's =head1 SYNOPSIS use Data::Uniqid qw ( suniqid uniqid luniqid ); $id = suniqid; $id = uniqid; $id = luniqid; =head1 DESCRIPTION Data::Uniqid provides three simple routines for generating unique ids. These ids are coded with a Base62 systen to make them short and handy (e.g. to use it as part of a URL). suinqid genrates a very short id valid only for the localhost and with a liftime of 1 day uniqid generates a short id valid on the local host luniqid generates a long id valid everywhere and ever =head1 AUTHOR Mike Wesemann, <mwx@gmx.de> =head1 SEE ALSO L. =cut libdata-uniqid-perl-0.12/test.pl000066400000000000000000000013411256561121300166000ustar00rootroot00000000000000use Test; BEGIN { plan tests => 4 }; use Data::Uniqid qw ( suniqid uniqid luniqid ) ; print "suniqid -> " . suniqid . "\n"; print "uniqid -> " . uniqid . "\n"; print "luniqid -> " . luniqid . "\n"; for (0..100) { $id=suniqid; if ($id{$id}) {;$err++;} $id{$id}++; } if ($err>0) {;ok(0);} else {;ok(1);} for (0..100) { $id=uniqid; if ($id{$id}) {;$err++;} $id{$id}++; } if ($err>0) {;ok(0);} else {;ok(1);} for (0..100) { $id=luniqid; if ($id{$id}) {;$err++;} $id{$id}++; } if ($err>0) {;ok(0);} else {;ok(1);} use Sys::Hostname; my($ia,$ib,$ic,$id)=unpack("C4", (gethostbyname(hostname()))[4]); if ($ia=~/\d+/ && $ia>0 && $ib=~/\d+/ && $ib>0 && $ic=~/\d+/ && $ic>0 && $id=~/\d+/ && $id>0 ) {;ok(1);} else {;ok(0);}