Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
robertkrimen committed Jun 10, 2009
0 parents commit 89dbc0c
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .cvsignore
@@ -0,0 +1,10 @@
blib*
Makefile
Makefile.old
Build
_build*
pm_to_blib*
*.tar.gz
.lwpcookies
Data-TUID-*
cover_db
5 changes: 5 additions & 0 deletions .screenrc
@@ -0,0 +1,5 @@
source $HOME/.screenrc

screen 0
stuff "[ -s Session.vim ] || vim -c 'mks!' -c 'quit'; vim -S \015"
screen 1
Empty file added Changes
Empty file.
23 changes: 23 additions & 0 deletions GNUmakefile
@@ -0,0 +1,23 @@
.PHONY: all test clean distclean dist

all: test

dist:
rm -rf inc META.y*ml
perl Makefile.PL
$(MAKE) -f Makefile dist

install distclean tardist: Makefile
$(MAKE) -f $< $@

test: Makefile
TEST_RELEASE=1 $(MAKE) -f $< $@

Makefile: Makefile.PL
perl $<

clean: distclean

reset: clean
perl Makefile.PL
$(MAKE) test
4 changes: 4 additions & 0 deletions MANIFEST
@@ -0,0 +1,4 @@
Changes
MANIFEST
Makefile.PL
README
40 changes: 40 additions & 0 deletions Makefile.PL
@@ -0,0 +1,40 @@
use inc::Module::Install;

name 'Data-TUID';
all_from 'lib/Data/TUID.pm';
author 'Robert Krimen <rkrimen@cpan.org>';
license 'perl';

resources repository => 'http://github.com/robertkrimen/Data-TUID/tree/master';

{
require ExtUtils::MakeMaker;
use strict;
no strict 'refs';

my $libscan = \&{"ExtUtils::MM_Any::libscan"};
*{"ExtUtils::MM_Any::libscan"} = sub {
return '' unless $libscan->(@_);
return '' if $_[1] =~ /\.sw[p-z]$/;
return $_[1];
};
}

{
map { my ($pk, $vr) = split m/\s/; build_requires $pk => $vr || 0 } grep { ! /^\s*#/ } split m/\n/, <<_END_;
Test::Most
_END_

map { my ($pk, $vr) = split m/\s/; requires $pk => $vr || 0 } grep { ! /^\s*#/ } split m/\n/, <<_END_;
_END_
}

if (-e 'inc/.author') {
my $all_from = join '/', 'lib', split m/-/, name . '.pm';
`perldoc -tF $all_from > README` if ! -e 'README' || (stat $all_from)[9] > (stat 'README')[9];
}

auto_install;

WriteAll;

46 changes: 46 additions & 0 deletions README
@@ -0,0 +1,46 @@
NAME
Data::TUID -

VERSION
Version 0.01

AUTHOR
Robert Krimen, "<rkrimen at cpan.org>"

BUGS
Please report any bugs or feature requests to "bug-data-tuid at
rt.cpan.org", or through the web interface at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-TUID>. I will be
notified, and then you'll automatically be notified of progress on your
bug as I make changes.

SUPPORT
You can find documentation for this module with the perldoc command.

perldoc Data::TUID

You can also look for information at:

* RT: CPAN's request tracker

<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-TUID>

* AnnoCPAN: Annotated CPAN documentation

<http://annocpan.org/dist/Data-TUID>

* CPAN Ratings

<http://cpanratings.perl.org/d/Data-TUID>

* Search CPAN

<http://search.cpan.org/dist/Data-TUID/>

ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2009 Robert Krimen, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

110 changes: 110 additions & 0 deletions lib/Data/TUID.pm
@@ -0,0 +1,110 @@
package Data::TUID;

use warnings;
use strict;

=head1 NAME
Data::TUID - A smaller and more communicable pseudo-UUID
=head1 VERSION
Version 0.01
=cut

our $VERSION = '0.01';

use Encode::Base32::Crockford qw/base32_encode/;
use Data::UUID::LibUUID qw/new_uuid_binary uuid_to_binary/;

sub generate {
return shift->tuid( @_ );
}

sub tuid {
my $self = shift;
my %given = @_;

my $uuid = $given{uuid} || new_uuid_binary;
$uuid = uuid_to_binary $uuid;

my @tuid = map { lc base32_encode $_ } unpack 'L*', new_uuid_binary;

my $all;
my $size = $given{size};
my $length = $given{length};
if ( $length && ( $length == -1 || $length >= 28 ) || $size && $size == -1 ) {
return join '', @tuid;
}
$length = 8 unless $length || $size;
if ( ! $all && $length ) {
$size = int( $length / 4 );
$size += $length % 4;
}
$size = $size < 1 ? 1 : $size > 7 ? 7 : $size;

@tuid = map { substr $_, -$size, $size } @tuid;
my $tuid = join '', @tuid;
$tuid = substr $tuid, 0, $length if $length;

return $tuid;
}

=head1 AUTHOR
Robert Krimen, C<< <rkrimen at cpan.org> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-data-tuid at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-TUID>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Data::TUID
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-TUID>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Data-TUID>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Data-TUID>
=item * Search CPAN
L<http://search.cpan.org/dist/Data-TUID/>
=back
=head1 ACKNOWLEDGEMENTS
=head1 COPYRIGHT & LICENSE
Copyright 2009 Robert Krimen, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut

1; # End of Data::TUID
9 changes: 9 additions & 0 deletions t/00-load.t
@@ -0,0 +1,9 @@
#!perl

use Test::More tests => 1;

BEGIN {
use_ok( 'Data::TUID' );
}

diag( "Testing Data::TUID $Data::TUID::VERSION, Perl $], $^X" );
19 changes: 19 additions & 0 deletions t/01-basic.t
@@ -0,0 +1,19 @@
#!/usr/bin/perl -w

use strict;
use warnings;

use Test::Most;

plan qw/no_plan/;

use Data::TUID;

is( length Data::TUID->tuid, 8 );
is( length Data::TUID->tuid( size => 1 ), 4 );
is( length Data::TUID->tuid( size => 2 ), 8 );
is( length Data::TUID->tuid( length => 5 ), 5 );
is( length Data::TUID->tuid( length => 20 ), 20 );
is( length Data::TUID->tuid( size => 5 ), 20 );

warn Data::TUID::->tuid( length => -1 );
55 changes: 55 additions & 0 deletions xt/boilerplate.t
@@ -0,0 +1,55 @@
#!perl -T

use strict;
use warnings;
use Test::More tests => 3;

sub not_in_file_ok {
my ($filename, %regex) = @_;
open( my $fh, '<', $filename )
or die "couldn't open $filename for reading: $!";

my %violated;

while (my $line = <$fh>) {
while (my ($desc, $regex) = each %regex) {
if ($line =~ $regex) {
push @{$violated{$desc}||=[]}, $.;
}
}
}

if (%violated) {
fail("$filename contains boilerplate text");
diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
} else {
pass("$filename contains no boilerplate text");
}
}

sub module_boilerplate_ok {
my ($module) = @_;
not_in_file_ok($module =>
'the great new $MODULENAME' => qr/ - The great new /,
'boilerplate description' => qr/Quick summary of what the module/,
'stub function definition' => qr/function[12]/,
);
}

TODO: {
local $TODO = "Need to replace the boilerplate text";

not_in_file_ok(README =>
"The README is used..." => qr/The README is used/,
"'version information here'" => qr/to provide version information/,
);

not_in_file_ok(Changes =>
"placeholder date/time" => qr(Date/time)
);

module_boilerplate_ok('lib/Data/TUID.pm');


}

18 changes: 18 additions & 0 deletions xt/pod-coverage.t
@@ -0,0 +1,18 @@
use strict;
use warnings;
use Test::More;

# Ensure a recent version of Test::Pod::Coverage
my $min_tpc = 1.08;
eval "use Test::Pod::Coverage $min_tpc";
plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
if $@;

# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
# but older versions don't recognize some common documentation styles
my $min_pc = 0.18;
eval "use Pod::Coverage $min_pc";
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
if $@;

all_pod_coverage_ok();
12 changes: 12 additions & 0 deletions xt/pod.t
@@ -0,0 +1,12 @@
#!perl -T

use strict;
use warnings;
use Test::More;

# Ensure a recent version of Test::Pod
my $min_tp = 1.22;
eval "use Test::Pod $min_tp";
plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;

all_pod_files_ok();

0 comments on commit 89dbc0c

Please sign in to comment.