File Coverage

blib/lib/CPAN/Testers/Common/Utils.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 25 25 100.0


line stmt bran cond sub pod time code
1             #
2             # This file is part of CPAN-Testers-Common-Utils
3             #
4             # This software is Copyright (c) 2010 by David A Golden.
5             #
6             # This is free software, licensed under:
7             #
8             # The Apache License, Version 2.0, January 2004
9             #
10 1     1   489851 use strict;
  1         3  
  1         40  
11 1     1   6 use warnings;
  1         82  
  1         64  
12             package CPAN::Testers::Common::Utils;
13             BEGIN {
14 1     1   16 $CPAN::Testers::Common::Utils::VERSION = '0.002';
15             }
16             # ABSTRACT: Utility functions for CPAN Testers modules
17              
18 1     1   8 use Exporter ();
  1         2  
  1         392  
19             our @ISA = qw/Exporter/;
20             our @EXPORT_OK = qw(
21             nntp_to_guid
22             guid_to_nntp
23             );
24             our %EXPORT_TAGS = (
25             all => [@EXPORT_OK]
26             );
27              
28             #--------------------------------------------------------------------------#
29             # NNTP <-> GUID
30             #--------------------------------------------------------------------------#
31              
32             # Base GUID generated with:
33             # Data::UUID->new->create_from_name_str(
34             # NameSpace_URL, "http://nntp.x.perl.org/group/perl.cpan.testers"
35             # );
36              
37             # Lower case is canonical
38             my $base_guid = "ed372d00-b19f-3f77-b713-d32bba55d77f";
39              
40             # strip leading zeros on extraction
41             my $nntp_re = qr{\A0*([0-9]{1,7})-b19f-3f77-b713-d32bba55d77f$};
42              
43             sub nntp_to_guid {
44 2     2 1 11 my ($nntp_id) = @_;
45 2         4 my $guid = $base_guid;
46 2         11 substr($guid, 0, 8, sprintf("%08d",$nntp_id)); # zero padded
47 2         16 return $guid;
48             }
49              
50             sub guid_to_nntp {
51 3     3 1 5 my ($guid) = @_;
52 3         18 my ($nntp_id) = $guid =~ $nntp_re;
53 3         13 return $nntp_id;
54             }
55              
56             1;
57              
58              
59              
60             =pod
61              
62             =head1 NAME
63              
64             CPAN::Testers::Common::Utils - Utility functions for CPAN Testers modules
65              
66             =head1 VERSION
67              
68             version 0.002
69              
70             =head1 SYNOPSIS
71              
72             use CPAN::Testers::Common::Utils ':all';
73            
74             # NNTP ID <=> GUID mapping
75             $guid = nntp_to_guid( $nntp_id );
76             $nntp_id = guid_to_nntp( $guid );
77              
78             =head1 DESCRIPTION
79              
80             This module contains common utility functions for use by other CPAN Testers
81             modules
82              
83             =head1 USAGE
84              
85             =head2 Mapping NNTP IDs to GUIDs
86              
87             Legacy CPAN Testers reports were sent via email and made available via an
88             NNTP group, CEperl.cpan.testersE. Reports were 'indexed' by their NNTP ID.
89             The next generation of CPAN Testers uses a GUID URN to identify reports.
90              
91             Old reports with an NNTP ID are mapped to GUIDs by replacing the first 8
92             hex characters of a common 'base GUID' with a zero-padded decimal
93             representation of the NNTP ID.
94              
95             XXXXXXXX-b19f-3f77-b713-d32bba55d77f
96              
97             Such GUID URNs are visually distinctive and have the nice feature of
98             sorting earlier than second-generated report GUIDs based on a timestamp.
99              
100             Two translation functions are provided for convenience.
101              
102             =head3 C<<< nntp_to_guid >>>
103              
104             $guid = nntp_to_guid( $nntp_id );
105              
106             Given a numeric NNTP ID, returns a standard string-form GUID. (No range
107             checking is done.) Examples:
108              
109             nntp_to_guid( 51432 ); # 00051432-b19f-3f77-b713-d32bba55d77f
110             nntp_to_guid( 6171265 ); # 06171265-b19f-3f77-b713-d32bba55d77f
111              
112             =head3 C<<< guid_to_nntp >>>
113              
114             $guid = nntp_to_guid( $nntp_id );
115              
116             Given a GUID string of the form described above, returns the decimal number
117             in the first 8 characaters. Examples:
118              
119             guid_to_nntp( '00051432-b19f-3f77-b713-d32bba55d77f' ); # 51432
120             guid_to_nntp( '06171265-b19f-3f77-b713-d32bba55d77f' ); # 6171265
121              
122             If the GUID string is not derived from the base GUID, this function
123             returns C<<< undef >>>.
124              
125             =head1 BUGS
126              
127             Please report any bugs or feature requests using the CPAN Request Tracker
128             web interface at L
129              
130             When submitting a bug or request, please include a test-file or a patch to an
131             existing test-file that illustrates the bug or desired feature.
132              
133             =head1 SEE ALSO
134              
135             =over
136              
137             =item *
138              
139             Data::GUID::Any
140              
141             =back
142              
143             =head1 AUTHOR
144              
145             David A Golden
146              
147             =head1 COPYRIGHT AND LICENSE
148              
149             This software is Copyright (c) 2010 by David A Golden.
150              
151             This is free software, licensed under:
152              
153             The Apache License, Version 2.0, January 2004
154              
155             =cut
156              
157              
158             __END__