This file is indexed.

/usr/share/perl5/RDF/DOAP/Lite.pm is in librdf-doap-lite-perl 0.002-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
use 5.008004;
use strict;
use warnings;
use utf8;

package RDF::DOAP::Lite;

our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION   = '0.002';

use CPAN::Meta    2.110320  qw();
use Scalar::Util  1.24      qw( openhandle );

# ============= helper functions =============

sub parse_person
{
	$_[0] =~ m{ \A \s*
		(\S.+)
		(?:
			\s+ \((\w+)\)
		)
		(?:
			\s+ <(?:mailto\:)?(.+)>
		)
	\s* \z }ix and return ($1, $2, $3);
	
	$_[0] =~ m{ \A \s*
		(\S.+)
		(?:
			\s+ <(?:mailto\:)?(.+)>
		)
	\s* \z }ix and return ($1, undef, $2);
	
	return $_[0];
}

{
	my %TURTLE = ( "\t" => "\\t", "\n" => "\\n", "\r" => "\\r", "\"" => "\\\"", "\\" => "\\\\" );
	sub turtle_literal
	{
		no warnings 'uninitialized';
		local $_ = $_[0];
		return q[""] if $_ eq '';
		s{([\t\n\r\"\\])}{$TURTLE{$1}}sg;
		qq("$_");
	}
}

sub turtle_person
{
	my ($name, $nick, $mbox) = parse_person @_;

	unless (defined $nick or defined $mbox)
	{
		return '[ a foaf:Person ]' unless defined $name;
		return sprintf('[ a foaf:Person; rdfs:label %s ]', turtle_literal $name);
	}

	my $person = '[ a foaf:Person';
	$person .= sprintf('; foaf:name %s', turtle_literal $name) if defined $name;
	$person .= sprintf('; foaf:nick %s', turtle_literal $nick) if defined $nick;
	$person .= sprintf('; foaf:mbox <mailto:%s>', $mbox) if defined $mbox;
	$person .= ' ]';
}

{
	my %XML = ('&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;');
	sub xml_literal
	{
		local $_ = shift;
		s{([&"<>])}{$XML{$1}}sg;
		return $_;
	}
}

sub xml_person
{
	my ($name, $nick, $mbox) = parse_person @_;
	
	unless (defined $nick or defined $mbox)
	{
		return '<foaf:Person />' unless defined $name;
		return sprintf('<foaf:Person rdfs:label="%s" />', xml_literal $name);
	}
	
	my $person = "<foaf:Person>\n";
	$person .= sprintf("      <foaf:name>%s</foaf:name>\n", xml_literal $name) if defined $name;
	$person .= sprintf("      <foaf:nick>%s</foaf:nick>\n", xml_literal $nick) if defined $nick;
	$person .= sprintf("      <foaf:mbox rdf:resource=\"mailto:%s\" />\n", xml_literal $mbox) if defined $mbox;
	$person .= "    </foaf:Person>";
	
	return $person;
}

sub rdf_datetype
{
	($_[0] =~ m{ \A [0-9]{4} - [0-9]{2} - [0-9]{2} \z }x) ? 'date' : 'dateTime';
}

# ============= class definition =============

sub new     { my $c = shift; bless { @_==1 ? %{$_[0]} : @_ }, $c }
sub meta    { $_[0]{meta} }
sub changes { $_[0]{changes} }

my %LICENSE = qw(
	agpl_3          http://www.gnu.org/licenses/agpl-3.0.txt
	apache_1_1      http://www.apache.org/licenses/LICENSE-1.1
	apache_2_0      http://www.apache.org/licenses/LICENSE-2.0.txt
	artistic_1      http://www.perlfoundation.org/artistic_license_1_0
	artistic_2      http://www.perlfoundation.org/artistic_license_2_0
	bsd             http://www.opensource.org/licenses/bsd-license.php
	freebsd         http://www.freebsd.org/copyright/freebsd-license.html
	gfdl_1_2        http://www.gnu.org/licenses/fdl-1.2.html
	gfdl_1_3        http://www.gnu.org/licenses/fdl-1.3.html
	gpl_1           http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt
	gpl_2           http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
	gpl_3           http://www.gnu.org/licenses/gpl-3.0.txt
	lgpl_2_1        http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
	lgpl_3_0        http://www.gnu.org/licenses/lgpl-3.0.txt
	mit             http://www.opensource.org/licenses/mit-license.php
	mozilla_1_0     http://www.mozilla.org/MPL/MPL-1.0.txt
	mozilla_1_1     http://www.mozilla.org/MPL/MPL-1.1.txt
	openssl         http://www.openssl.org/source/license.html
	perl            http://dev.perl.org/licenses/
	perl_5          http://dev.perl.org/licenses/
	qpl_1_0         http://trolltech.com/products/qt/licenses/licensing/qpl
	ssleay          http://h71000.www7.hp.com/doc/83final/BA554_90007/apcs02.html
	sun             http://www.openoffice.org/licenses/sissl_license.html
	zlib            http://www.zlib.net/zlib_license.html
);

my %REPO = qw(
	cvs      CVS
	git      Git
	hg       Hg
	svn      SVN
);

sub doap_ttl
{
	my $self = shift;
	my $fh = openhandle($_[0])
		? $_[0]
		: do { open my $fh, '>', $_[0] or die("Could not open $_[0]: $!"); $fh };
	
	print {$fh} <<'	HEADER', "\n";
@prefix :     <http://usefulinc.com/ns/doap#>.
@prefix dc:   <http://purl.org/dc/terms/>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#>.
	HEADER
	
	my $meta = $self->meta or die("no meta!");
	my $res  = $meta->resources;
	my $uri  = $res->{X_identifier} ? "<$res->{X_identifier}>" : '[]';
	
	printf {$fh} "$uri\n";
	printf {$fh} "  a :Project;\n";
	printf {$fh} "  :name %s;\n", turtle_literal($_) for grep defined, $meta->name;
	printf {$fh} "  :shortdesc %s;\n", turtle_literal($_) for grep defined, $meta->abstract;
	printf {$fh} "  :description %s;\n", turtle_literal($_) for grep defined, $meta->description;
	printf {$fh} "  :category [ rdfs:label %s ];\n", turtle_literal($_) for grep defined, $meta->keywords;
	printf {$fh} "  :developer %s;\n", turtle_person($_) for grep defined, $meta->authors;
	printf {$fh} "  :helper %s;\n", turtle_person($_) for grep defined, @{ $meta->{x_contributors} || [] };
	printf {$fh} "  :license <%s>;\n", $_ for map { $LICENSE{$_} || ()  } $meta->licenses;
	printf {$fh} "  :homepage <%s>;\n", $_ for grep defined, $res->{homepage};
	printf {$fh} "  :bug-database <%s>;\n", $_ for grep defined, $res->{bugtracker}{web};
	if (my $repo = $res->{repository})
	{
		printf {$fh} "  :repository [\n";
		printf {$fh} "    a :%sRepository;\n", $_ for map { $REPO{$_} || '' } $repo->{type};
		printf {$fh} "    :browse <%s>;\n", $_ for grep defined, $repo->{web};
		printf {$fh} "    :location <%s>;\n", $_ for grep defined, $repo->{url};
		printf {$fh} "  ];\n";
	}
	for my $r (map $_->releases, grep defined, $self->changes)
	{
		$r->date
			? printf {$fh} "  :release [ a :Version; :revision %s^^xsd:string; dc:issued %s^^xsd:%s ];\n", turtle_literal($r->version), turtle_literal($r->date), rdf_datetype($r->date)
			: printf {$fh} "  :release [ a :Version; :revision %s^^xsd:string ];\n", turtle_literal($r->version)
	}
	printf {$fh} "  :programming-language %s.\n", turtle_literal("Perl");
}

sub doap_xml
{
	my $self = shift;	
	my $fh = openhandle($_[0])
		? $_[0]
		: do { open my $fh, '>', $_[0] or die("Could not open $_[0]: $!"); $fh };
	
	print {$fh} <<'	HEADER';
<?xml version="1.0" encoding="UTF-8" ?>
<Project
  xmlns="http://usefulinc.com/ns/doap#"
  xmlns:dc="http://purl.org/dc/terms/"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
	HEADER
	
	my $meta = $self->meta or die("no meta!");
	my $res  = $meta->resources;
	
	if ($res->{X_identifier})
	{
		printf {$fh} "  rdf:about=\"%s\">\n", xml_literal($res->{X_identifier});
	}
	else
	{
		printf {$fh} "  >\n";
	}
	
	printf {$fh} "  <name>%s</name>\n", xml_literal($_) for grep defined, $meta->name;
	printf {$fh} "  <shortdesc>%s</shortdesc>\n", xml_literal($_) for grep defined, $meta->abstract;
	printf {$fh} "  <description>%s</description>\n", xml_literal($_) for grep defined, $meta->description;
	printf {$fh} "  <category rdfs:label=\"%s\" />\n", xml_literal($_) for grep defined, $meta->keywords;
	printf {$fh} "  <developer>\n    %s\n  </developer>\n", xml_person($_) for grep defined, $meta->authors;
	printf {$fh} "  <helper>\n    %s\n  </helper>\n", xml_person($_) for grep defined, @{ $meta->{x_contributors} || [] };
	printf {$fh} "  <license rdf:resource=\"%s\" />\n", xml_literal($_) for map { $LICENSE{$_} || ()  } $meta->licenses;
	printf {$fh} "  <homepage rdf:resource=\"%s\" />\n", xml_literal($_) for grep defined, $res->{homepage};
	printf {$fh} "  <bug-database rdf:resource=\"%s\" />\n", xml_literal($_) for grep defined, $res->{bugtracker}{web};
	if (my $repo = $res->{repository})
	{
		printf {$fh} "  <repository>\n";
		printf {$fh} "    <%sRepository>\n", $_ for map { $REPO{$_} || '' } $repo->{type};
		printf {$fh} "      <browse rdf:resource=\"%s\" />\n", xml_literal($_) for grep defined, $repo->{web};
		printf {$fh} "      <location rdf:resource=\"%s\" />\n", xml_literal($_) for grep defined, $repo->{url};
		printf {$fh} "    </%sRepository>\n", $_ for map { $REPO{$_} || '' } $repo->{type};
		printf {$fh} "  </repository>\n";
	}
	for my $r (map $_->releases, grep defined, $self->changes)
	{
		$r->date
			? printf {$fh} "  <release>\n    <Version>\n      <revision rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">%s</revision>\n      <dc:issued rdf:datatype=\"http://www.w3.org/2001/XMLSchema#%s\">%s</dc:issued>\n    </Version>\n  </release>\n", xml_literal($r->version), rdf_datetype($r->date), xml_literal($r->date)
			: printf {$fh} "  <release>\n    <Version>\n      <revision rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">%s</revision>\n    </Version>\n  </release>\n", xml_literal($r->version)
	}
	printf {$fh} "  <programming-language>%s</programming-language>\n", xml_literal("Perl");
	printf {$fh} "</Project>\n";
}

1;

__END__

=pod

=encoding utf-8

=head1 NAME

RDF::DOAP::Lite - write DOAP data quickly and easily

=head1 SYNOPSIS

   use CPAN::Changes;
   use CPAN::Meta;
   use RDF::DOAP::Lite;
   
   my $changes = CPAN::Changes->load('Changes');
   my $meta    = CPAN::Meta->load_file('META.json');
   my $doap    = RDF::DOAP::Lite->new(meta => $meta, changes => $changes);
   
   $doap->doap_ttl('doap.ttl');
   $doap->doap_xml('doap.xml');

=head1 DESCRIPTION

This is a small companion module to L<RDF::DOAP>, enabling you to
output DOAP data easily from standard CPAN distribution files.

=head2 The Straight DOAP

So what is DOAP? This explanation is lifted from
L<Wikipedia|http://en.wikipedia.org/wiki/DOAP>.

I<< DOAP (Description of a Project) is an RDF Schema and XML vocabulary
to describe software projects, in particular free and open source
software. >>

I<< It was created and initially developed by Edd Dumbill to convey
semantic information associated with open source software projects. >>

I<< It is currently used in the Mozilla Foundation's project page and
in several other software repositories, notably the Python Package
Index. >>

=head2 Constructor

=over

=item C<< new(%attributes) >>

Moose-style constructor (though this module does not use L<Moose>).

=back

=head2 Attributes

=over

=item C<< meta >>

This is a required attribute; a L<CPAN::Meta> object.

=item C<< changes >>

This is an optional attribute; a L<CPAN::Changes> object.

=back

=head2 Methods

=over

=item C<< doap_ttl($file) >>

Writes DOAP data in the Turtle serialization to the file. The file may
be provided as a filename (string) or a file handle.

=item C<< doap_xml($file) >>

Writes DOAP data in the RDF/XML serialization to the file. The file may
be provided as a filename (string) or a file handle.

=back

=head1 BUGS

Please report any bugs to
L<http://rt.cpan.org/Dist/Display.html?Queue=RDF-DOAP-Lite>.

=head1 SEE ALSO

This module comes with a bundled command-line tool, L<cpan2doap>.

For parsing DOAP data, see L<RDF::DOAP>.

For general RDF processing, use L<RDF::Trine> and L<RDF::Query>.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT AND LICENCE

This software is copyright (c) 2013-2014 by Toby Inkster.

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

=head1 DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.