Permalink
Browse files

have guid_to_nntp return undef if not an NNTP-style GUID

  • Loading branch information...
1 parent d67c363 commit e15ee02a1e7042693d3fd8f4d4ed89509271de91 @xdg xdg committed Jun 4, 2010
Showing with 16 additions and 5 deletions.
  1. +3 −1 Changes
  2. +8 −3 lib/CPAN/Testers/Common/Utils.pm
  3. +5 −1 t/uuid.t
View
@@ -2,7 +2,9 @@ Revision history for CPAN-Testers-Common-Utils
{{ $NEXT }}
- - distribution managed with Dist::Zilla
+ - have guid_to_nntp return undef if GUID is not a converted NNTP GUID
+
+ - distribution now managed with Dist::Zilla
0.001 Sun Jan 17 22:34:30 EST 2010
@@ -25,6 +25,9 @@ our %EXPORT_TAGS = (
# Lower case is canonical
my $base_guid = "ed372d00-b19f-3f77-b713-d32bba55d77f";
+# strip leading zeros on extraction
+my $nntp_re = qr{\A0*([0-9]{1,7})-b19f-3f77-b713-d32bba55d77f$};
+
sub nntp_to_guid {
my ($nntp_id) = @_;
my $guid = $base_guid;
@@ -34,7 +37,7 @@ sub nntp_to_guid {
sub guid_to_nntp {
my ($guid) = @_;
- my ($nntp_id) = $guid =~ m{\A0*([0-9]{1,7})}; # strip leading zeros
+ my ($nntp_id) = $guid =~ $nntp_re;
return $nntp_id;
}
@@ -91,12 +94,14 @@ checking is done.) Examples:
$guid = nntp_to_guid( $nntp_id );
Given a GUID string of the form described above, returns the decimal number
-in the first 8 characaters. (Again, there is no error checking that
-the GUID is properly formatted.) Examples:
+in the first 8 characaters. Examples:
guid_to_nntp( '00051432-b19f-3f77-b713-d32bba55d77f' ); # 51432
guid_to_nntp( '06171265-b19f-3f77-b713-d32bba55d77f' ); # 6171265
+If the GUID string is not derived from the base GUID, this function
+returns {undef}.
+
= BUGS
Please report any bugs or feature requests using the CPAN Request Tracker
View
@@ -1,8 +1,12 @@
use CPAN::Testers::Common::Utils qw(nntp_to_guid guid_to_nntp);
-use Test::More tests => 4;
+use Test::More tests => 5;
is nntp_to_guid(51432), '00051432-b19f-3f77-b713-d32bba55d77f';
is nntp_to_guid(6171265), '06171265-b19f-3f77-b713-d32bba55d77f';
is guid_to_nntp('00051432-b19f-3f77-b713-d32bba55d77f'), 51432;
is guid_to_nntp('06171265-b19f-3f77-b713-d32bba55d77f'), 6171265;
+
+# not an NNTP-based GUID
+is guid_to_nntp('06171265-6fe5-11df-857c-0018f34ec37c'), undef;
+

0 comments on commit e15ee02

Please sign in to comment.