Commits

Toby Inkster  committed fa08f6d

Ubercool RDF-driven build system.

  • Participants

Comments (0)

Files changed (10)

+use inc::Module::Package 'RDF:standard';

File Module-Install-DOAP-0.001.tar.gz

Binary file added.
+- Document which parts of DOAP, and which extension vocabularies this module uses, and how that's mapped to META.yml, etc.
+- Look at a better way of representing dependencies.

File lib/Module/Install/Admin/DOAP.pm

+package Module::Install::Admin::DOAP;
+
+use 5.008;
+use base qw(Module::Install::Base);
+use strict;
+
+use File::Spec;
+use Module::Install::Admin::RDF;
+use RDF::Trine;
+use URI::file;
+
+our $VERSION = '0.001';
+
+use RDF::Trine::Namespace qw[RDF RDFS OWL XSD];
+my $CPAN = RDF::Trine::Namespace->new('http://purl.org/NET/cpan-uri/terms#');
+my $DC   = RDF::Trine::Namespace->new('http://purl.org/dc/terms/');
+my $DOAP = RDF::Trine::Namespace->new('http://usefulinc.com/ns/doap#');
+my $FOAF = RDF::Trine::Namespace->new('http://xmlns.com/foaf/0.1/');
+my $NFO  = RDF::Trine::Namespace->new('http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#');
+my $SKOS = RDF::Trine::Namespace->new('http://www.w3.org/2004/02/skos/core#');
+
+sub doap_metadata
+{
+	my ($self, $uri) = @_;
+	
+	unless (defined $uri)
+	{
+		my @dirs = File::Spec->splitdir(File::Spec->rel2abs(File::Spec->curdir));
+		$uri = sprintf('http://purl.org/NET/cpan-uri/dist/%s/project', $dirs[-1]);
+	}
+	unless (ref $uri)
+	{
+		$uri = RDF::Trine::Node::Resource->new($uri);
+	}
+
+	my $metadata = sub {
+		$self->_top->call(@_);
+		};
+
+	my $model = Module::Install::Admin::RDF::rdf_metadata($self);
+
+	my $name;
+	NAME: foreach ($model->objects_for_predicate_list($uri, $DOAP->name, $FOAF->name, $RDFS->label))
+	{
+		next NAME unless $_->is_literal;
+		$name = $_->literal_value;
+		$metadata->(name => $_->literal_value);
+		last NAME;
+	}
+
+	my $mname;
+	MNAME: foreach ($model->objects_for_predicate_list($uri, $CPAN->module_name))
+	{
+		next MNAME unless $_->is_literal;
+		$mname = $_->literal_value;
+		$metadata->(module_name => $_->literal_value);
+		last MNAME;
+	}
+	if (defined $name and !defined $mname)
+	{
+		$mname = $name;
+		$mname =~ s/-/::/g;
+		$metadata->(module_name => $mname);
+	}
+
+	DESC: foreach ($model->objects_for_predicate_list($uri, $DOAP->shortdesc, $DC->abstract))
+	{
+		next DESC unless $_->is_literal;
+		$metadata->(abstract => $_->literal_value);
+		last DESC;
+	}
+
+	LICENSE: foreach ($model->objects_for_predicate_list($uri, $DOAP->license, $DC->license))
+	{
+		next LICENSE unless $_->is_resource;
+		
+		my $license_code = {
+			'http://www.gnu.org/licenses/agpl-3.0.txt'              => 'open_source',
+			'http://www.apache.org/licenses/LICENSE-1.1'            => 'apache_1_1',
+			'http://www.apache.org/licenses/LICENSE-2.0'            => 'apache',
+			'http://www.apache.org/licenses/LICENSE-2.0.txt'        => 'apache',
+			'http://www.perlfoundation.org/artistic_license_1_0'    => 'artistic',
+			'http://opensource.org/licenses/artistic-license.php'   => 'artistic',
+			'http://www.perlfoundation.org/artistic_license_2_0'    => 'artistic_2',
+			'http://opensource.org/licenses/artistic-license-2.0.php'  => 'artistic_2',
+			'http://www.opensource.org/licenses/bsd-license.php'    => 'bsd',
+			'http://creativecommons.org/publicdomain/zero/1.0/'     => 'unrestricted',
+			'http://www.freebsd.org/copyright/freebsd-license.html' => 'open_source',
+			'http://www.gnu.org/copyleft/fdl.html'                  => 'open_source',
+			'http://www.opensource.org/licenses/gpl-license.php'    => 'gpl',
+			'http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt'  => 'gpl',
+			'http://www.opensource.org/licenses/gpl-2.0.php'        => 'gpl2',
+			'http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt'  => 'gpl2',
+			'http://www.opensource.org/licenses/gpl-3.0.html'       => 'gpl3',
+			'http://www.gnu.org/licenses/gpl-3.0.txt'               => 'gpl3',
+			'http://www.opensource.org/licenses/lgpl-license.php'   => 'lgpl',
+			'http://www.opensource.org/licenses/lgpl-2.1.php'       => 'lgpl2',
+			'http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt' => 'lgpl2',
+			'http://www.opensource.org/licenses/lgpl-3.0.html'      => 'lgpl3',
+			'http://www.gnu.org/licenses/lgpl-3.0.txt'              => 'lgpl3',
+			'http://www.opensource.org/licenses/mit-license.php'    => 'mit',
+			'http://www.mozilla.org/MPL/MPL-1.0.txt'                => 'mozilla',
+			'http://www.mozilla.org/MPL/MPL-1.1.txt'                => 'mozilla',
+			'http://opensource.org/licenses/mozilla1.1.php'         => 'mozilla',
+			'http://www.openssl.org/source/license.html'            => 'open_source',
+			'http://dev.perl.org/licenses/'                         => 'perl',
+			'http://www.opensource.org/licenses/postgresql'         => 'open_source',
+			'http://trolltech.com/products/qt/licenses/licensing/qpl'  => 'open_source',
+			'http://h71000.www7.hp.com/doc/83final/BA554_90007/apcs02.html'  => 'unrestricted',
+			'http://www.openoffice.org/licenses/sissl_license.html' => 'open_source',
+			'http://www.zlib.net/zlib_license.html'                 => 'open_source',
+			}->{ $_->uri } || undef;
+
+		$metadata->(license => $license_code);
+		last LICENSE;
+	}
+	
+	my %resources;
+	($resources{license}) = 
+		map  { $_->uri }
+		grep { $_->is_resource }
+		$model->objects_for_predicate_list($uri, $DOAP->license, $DC->license);
+	($resources{homepage}) = 
+		map  { $_->uri }
+		grep { $_->is_resource }
+		$model->objects_for_predicate_list($uri, $DOAP->homepage, $FOAF->homepage, $FOAF->page);
+	($resources{bugtracker}) = 
+		map  { $_->uri }
+		grep { $_->is_resource }
+		$model->objects($uri, $DOAP->uri('bug-database'));
+	REPO: foreach my $repo ($model->objects($uri, $DOAP->repository))
+	{
+		next REPO if $repo->is_literal;
+		($resources{repository}) = 
+			map  { $_->uri }
+			grep { $_->is_resource }
+			$model->objects($repo, $DOAP->uri('browse'));
+		last REPO if $resources{repository};
+	}
+	($resources{MailingList}) = 
+		map  { $_->uri }
+		grep { $_->is_resource }
+		$model->objects($uri, $DOAP->uri('mailing-list'));
+	($resources{Wiki}) = 
+		map  { $_->uri }
+		grep { $_->is_resource }
+		$model->objects($uri, $DOAP->uri('wiki'));
+	$metadata->(resources => %resources);
+
+	my %keywords;
+	CATEGORY: foreach my $cat ($model->objects_for_predicate_list($uri, $DOAP->category, $DC->subject))
+	{
+		if ($cat->is_literal)
+		{
+			$keywords{ uc $cat->literal_value } = $cat->literal_value;
+		}
+		else
+		{
+			LABEL: foreach my $label ($model->objects_for_predicate_list($cat, $SKOS->prefLabel, $RDFS->label, $DOAP->name, $FOAF->name))
+			{
+				next LABEL unless $label->is_literal;
+				$keywords{ uc $label->literal_value } = $label->literal_value;
+				next CATEGORY;
+			}
+		}
+	}
+	$metadata->(keywords => sort values %keywords);
+	
+	my %authors;
+	AUTHOR: foreach my $author ($model->objects_for_predicate_list($uri, $DOAP->developer, $DOAP->maintainer, $FOAF->maker, $DC->creator))
+	{
+		my ($name) =
+			map  { $_->literal_value }
+			grep { $_->is_literal }
+			$model->objects_for_predicate_list($author, $FOAF->name, $RDFS->label);
+		my ($mbox) =
+			map  { my $x = $_->uri; $x =~ s/^mailto://i; $x; }
+			grep { $_->is_resource }
+			$model->objects_for_predicate_list($author, $FOAF->mbox);
+		
+		my $str = do
+			{
+				if ($name and $mbox)
+					{ "$name <$mbox>"; }
+				elsif ($name)
+					{ $name; }
+				elsif ($mbox)
+					{ $mbox; }
+				else
+					{ "$author"; }
+			};
+		$authors{uc $str} = $str;
+	}
+	$metadata->(authors => sort values %authors);
+
+	{
+		my @terms = qw(requires build_requires configure_requires recommends test_requires);
+		foreach my $term (@terms)
+		{
+			foreach my $dep ($model->objects($uri, $CPAN->$term))
+			{
+				if ($dep->is_literal)
+				{
+					my ($mod, $ver) = split /\s+/, $dep->literal_value;
+					$ver ||= 0;
+					$metadata->($term => $mod => $ver);
+				}
+				else
+				{
+					warn "Dunno what to do with ${dep}... we'll figure something out eventually.";
+				}
+			}
+		}
+	}
+
+	{
+		my @terms = qw(abstract_from author_from license_from perl_version_from readme_from version_from
+			no_index install_script requires_external_bin);
+		TERM: foreach my $term (@terms)
+		{
+			foreach my $val ($model->objects($uri, $CPAN->$term))
+			{
+				if ($val->is_literal)
+				{
+					$metadata->($term => $val->literal_value);
+					next TERM;
+				}
+				else
+				{
+					foreach my $name ($model->objects($val, $NFO->fileName))
+					{
+						if ($name->is_literal)
+						{
+							$metadata->($term => $name->literal_value);
+							next TERM;
+						}
+					}
+				}
+			}
+		}
+	}
+}
+
+1;

File lib/Module/Install/DOAP.pm

+package Module::Install::DOAP;
+
+use 5.008;
+use base qw(Module::Install::Base);
+use strict;
+
+our $VERSION = '0.001';
+our $AUTHOR_ONLY = 1;
+
+sub doap_metadata
+{
+	my $self = shift;
+	$self->admin->doap_metadata(@_) if $self->is_admin;
+}
+
+1;
+
+__END__
+=head1 NAME
+
+Module::Install::DOAP - generate META.yml data from DOAP
+
+=head1 SYNOPSIS
+
+In Makefile.PL:
+
+  rdf_metadata;
+  doap_metadata;
+  
+=head1 DESCRIPTION
+
+This Module::Install plugin generates your META.yml file from RDF data
+(especially DOAP) in your distribution's 'meta' directory.
+
+=head1 BUGS
+
+Please report any bugs to L<http://rt.cpan.org/>.
+
+=head1 SEE ALSO
+
+L<Module::Install>, L<Module::Install::DOAPChangeSets> .
+
+L<http://www.perlrdf.org/>.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2011 by Toby Inkster
+
+This library is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut

File meta/changes.ttl

+@prefix :        <http://usefulinc.com/ns/doap#> .
+@prefix dcs:     <http://ontologi.es/doap-changeset#> .
+@prefix dc:      <http://purl.org/dc/terms/> .
+@prefix foaf:    <http://xmlns.com/foaf/0.1/> .
+@prefix my:      <http://purl.org/NET/cpan-uri/dist/Module-Install-DOAP/> .
+@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix toby:    <http://tobyinkster.co.uk/#> .
+@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
+
+my:project :release my:v_0-001 .
+my:v_0-001
+
+	a               :Version ;
+	dc:issued       "2011-10-01"^^xsd:date ;
+	:revision       "0.001"^^xsd:string ;
+	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/Module-Install-DOAP-0.001.tar.gz> ;
+	rdfs:label      "Initial release" .
+

File meta/deps.ttl

+@prefix : <http://purl.org/NET/cpan-uri/terms#> .
+
+<http://purl.org/NET/cpan-uri/dist/Module-Install-DOAP/project>
+	:requires
+		"File::Spec 3.0" ,
+		"Module::Install 1.00" ,
+		"Module::Install::RDF 0.001" ,
+		"RDF::Trine 0.112" ,
+		"URI::file 4.0" ;
+	:test_requires
+		"Test::More 0.61" .

File meta/doap.ttl

+@prefix :        <http://usefulinc.com/ns/doap#> .
+@prefix dcs:     <http://ontologi.es/doap-changeset#> .
+@prefix dc:      <http://purl.org/dc/terms/> .
+@prefix foaf:    <http://xmlns.com/foaf/0.1/> .
+@prefix my:      <http://purl.org/NET/cpan-uri/dist/Module-Install-DOAP/> .
+@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix toby:    <http://tobyinkster.co.uk/#> .
+@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
+
+my:project
+
+	a               :Project ;
+	:name           "Module-Install-DOAP" ;
+	:shortdesc      "generate META.yml data from DOAP"@en ;
+	:programming-language  "Perl" ;
+	:homepage       <https://metacpan.org/release/Module-Install-DOAP> ;
+	:download-page  <https://metacpan.org/release/Module-Install-DOAP> ;
+	:bug-database   <http://rt.cpan.org/Dist/Display.html?Queue=Module-Install-DOAP> ;
+	:repository     [ a :SVNRepository ; :browse <http://goddamn.co.uk/svn-web/perlmods/browse/Module-Install-DOAP/> ] ;
+	:maintainer     toby:i ;
+	:developer      toby:i ;
+	:documenter     toby:i ;
+	:tester         toby:i ;
+	:created        "2011-09-30"^^xsd:date ;
+	:license        <http://dev.perl.org/licenses/> ;
+	:category
+		[ rdfs:label "RDF" ] ,
+		[ rdfs:label "Semantic Web" ] ,
+		[ rdfs:label "CPAN" ] ,
+		[ rdfs:label "DOAP" ] ,
+		[ rdfs:label "Metadata" ] ,
+		[ rdfs:label "Packaging" ] .
+
+toby:i
+
+	a               foaf:Person ;
+	foaf:name       "Toby Inkster" ;
+	foaf:homepage   <http://tobyinkster.co.uk/> ;
+	foaf:page       <https://metacpan.org/author/TOBYINK> ;
+	foaf:mbox       <mailto:tobyink@cpan.org> ;
+	<http://www.w3.org/2002/07/owl#sameAs> <http://purl.org/NET/cpan-uri/person/tobyink> .

File meta/makefile.ttl

+@prefix : <http://purl.org/NET/cpan-uri/terms#> .
+
+<http://purl.org/NET/cpan-uri/dist/Module-Install-DOAP/project>
+	:perl_version_from _:main ;
+	:version_from _:main ;
+	:readme_from _:main .
+
+_:main <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName> "lib/Module/Install/DOAP.pm" .
+use Test::More tests => 2;
+BEGIN { use_ok('Module::Install::RDF') };
+BEGIN { use_ok('Module::Install::Admin::RDF') };