File Coverage

blib/lib/Perl/Meta.pm
Criterion Covered Total %
statement 28 29 96.5
branch 6 6 100.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 3 3 100.0
total 46 48 95.8


line stmt bran cond sub pod time code
1             package Perl::Meta;
2            
3 3     3   55407 use 5.005;
  3         12  
  3         131  
4             #use warnings;
5 3     3   18 use strict;
  3         6  
  3         123  
6            
7             =head1 NAME
8            
9             Perl::Meta - Extract metadata from perl/pod text.
10            
11             =head1 VERSION
12            
13             Version 0.02
14            
15             =cut
16            
17 3     3   17 use vars '$VERSION';
  3         18  
  3         2624  
18             $VERSION = '0.02';
19            
20            
21             =head1 SYNOPSIS
22            
23             use Perl::Meta;
24            
25             my $pv = Perl::Meta::extract_perl_version(' use 5.10.1;');
26             ...
27            
28             =head1 SUBROUTINES/METHODS
29            
30             =head2 extract_license
31            
32             Returns license code for META.yml/json from perl/pod text by matching several patterns.
33            
34             =head2 extract_perl_version
35            
36             Returns perl version required in perl text.
37            
38             =head2 extract_bugtracker
39            
40             Searches for bug tracker pod links in text. rt.cpan.org, github.com,
41             code.google.com are supported.
42            
43             =cut
44            
45             sub extract_license {
46 10     10 1 7875 my $pod = shift;
47 10         15 my $matched;
48 10   66     160 return _extract_license(
49             ($matched) = $pod =~ m/
50             (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?)
51             (=head \d.*|=cut.*|)\z
52             /xms
53             ) || _extract_license(
54             ($matched) = $pod =~ m/
55             (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?)
56             (=head \d.*|=cut.*|)\z
57             /xms
58             );
59             }
60            
61             sub _extract_license {
62 16 100   16   195 my $license_text = shift or return;
63 10         100 my @phrases = (
64             '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1,
65             '(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1,
66             'under the terms of either the GNU General Public License or the Artistic License' => 'perl', 1,
67             'Artistic and GPL' => 'perl', 1,
68             'GNU general public license' => 'gpl', 1,
69             'GNU public license' => 'gpl', 1,
70             'GNU lesser general public license' => 'lgpl', 1,
71             'GNU lesser public license' => 'lgpl', 1,
72             'GNU library general public license' => 'lgpl', 1,
73             'GNU library public license' => 'lgpl', 1,
74             'GNU Free Documentation license' => 'unrestricted', 1,
75             'GNU Affero General Public License' => 'open_source', 1,
76             '(?:Free)?BSD license' => 'bsd', 1,
77             'Artistic license 2\.0' => 'artistic_2', 1,
78             'Artistic license' => 'artistic', 1,
79             'Apache (?:Software )?license' => 'apache', 1,
80             'GPL' => 'gpl', 1,
81             'LGPL' => 'lgpl', 1,
82             'BSD' => 'bsd', 1,
83             'Artistic' => 'artistic', 1,
84             'MIT' => 'mit', 1,
85             'Mozilla Public License' => 'mozilla', 1,
86             'Q Public License' => 'open_source', 1,
87             'OpenSSL License' => 'unrestricted', 1,
88             'SSLeay License' => 'unrestricted', 1,
89             'zlib License' => 'open_source', 1,
90             'proprietary' => 'proprietary', 0,
91             );
92 10         40 while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
93 43         278 $pattern =~ s#\s+#\\s+#gs;
94 43 100       1297 if ( $license_text =~ /\b$pattern\b/i ) {
95 10         82 return $license;
96             }
97             }
98 0         0 return '';
99             }
100            
101            
102             sub extract_perl_version {
103 3 100   3 1 1425 if (
104             $_[0] =~ m/
105             ^\s*
106             (?:use|require) \s*
107             v?
108             ([\d_\.]+)
109             \s* ;
110             /ixms
111             ) {
112 2         6 my $perl_version = $1;
113 2         5 $perl_version =~ s{_}{}g;
114 2         5 return $perl_version;
115             } else {
116 1         3 return;
117             }
118             }
119            
120            
121             sub extract_bugtracker {
122 6     6 1 6668 my @links = $_[0] =~ m#L<(
123             https?\Q://rt.cpan.org/\E[^>]+|
124             https?\Q://github.com/\E[\w_]+/[\w_]+/issues|
125             https?\Q://code.google.com/p/\E[\w_\-]+/issues/list
126             )>#gx;
127 6         10 my %links;
128 6         21 @links{@links}=();
129 6         15 @links=keys %links;
130 6         187 return @links;
131             }
132            
133             =head1 AUTHOR
134            
135             Alexandr Ciornii, C<< >>
136            
137             =head1 BUGS
138            
139             Please report any bugs or feature requests to C, or through
140             the web interface at L. I will be notified, and then you'll
141             automatically be notified of progress on your bug as I make changes.
142            
143            
144            
145            
146             =head1 SUPPORT
147            
148             You can find documentation for this module with the perldoc command.
149            
150             perldoc Perl::Meta
151            
152            
153             You can also look for information at:
154            
155             =over 4
156            
157             =item * RT: CPAN's request tracker
158            
159             L
160            
161             =item * AnnoCPAN: Annotated CPAN documentation
162            
163             L
164            
165             =item * CPAN Ratings
166            
167             L
168            
169             =item * Search CPAN
170            
171             L
172            
173             =back
174            
175            
176             =head1 ACKNOWLEDGEMENTS
177            
178            
179             =head1 LICENSE AND COPYRIGHT
180            
181             Copyright 2010-2011 Alexandr Ciornii.
182             Copyright 2002 - 2011 Brian Ingerson, Audrey Tang and Adam Kennedy.
183            
184             This program is free software; you can redistribute it and/or modify it
185             under the terms of either: the GNU General Public License as published
186             by the Free Software Foundation; or the Artistic License.
187            
188             See http://dev.perl.org/licenses/ for more information.
189            
190            
191             =cut
192            
193             1; # End of Perl::Meta