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
|
package Module::Install::Admin::DOAPChangeSets;
use 5.008;
use parent qw(Module::Install::Base);
use strict;
use RDF::DOAP::ChangeSets;
use RDF::Trine;
use File::Slurp qw(slurp);
use URI::file;
use Module::Install::Base;
our $VERSION = '0.206';
sub _make_dcs
{
my ($self, $in, $fmt, $type) = @_;
unless (defined $self->{DCS})
{
my $model = eval {
require Module::Install::Admin::RDF;
Module::Install::Admin::RDF::rdf_metadata($self);
};
if (defined $model)
{
my $inuri = URI::file->new_abs("meta/");
$self->{DCS} = RDF::DOAP::ChangeSets->new($inuri, $model);
}
else
{
my @files_to_try = qw[meta/changes.ttl Changes.ttl];
while (@files_to_try and not defined $in)
{
my $f = shift @files_to_try;
$in = $f if -e $f;
}
die "meta/changes.ttl not found" unless $in;
my $data = slurp($in);
my $inuri = URI::file->new_abs($in);
$self->{DCS} = RDF::DOAP::ChangeSets->new($inuri, undef, $type, $fmt);
}
}
return $self->{DCS};
}
sub write_doap_changes
{
my $self = shift;
my $in = shift || undef;
my $out = shift || "Changes";
my $fmt = shift || "turtle";
my $type = shift || "auto";
_make_dcs($self, $in, $fmt, $type)->to_file($out);
}
sub write_doap_changes_xml
{
my $self = shift;
my $in = shift || undef;
my $out = shift || "Changes.xml";
my $fmt = shift || "turtle";
my $type = shift || "auto";
my $changeset = _make_dcs($self, $in, $fmt, $type);
my $rdfxml = RDF::Trine::Serializer::RDFXML->new(namespaces => {
dbug => 'http://ontologi.es/doap-bugs#',
dc => 'http://purl.org/dc/terms/',
dcs => 'http://ontologi.es/doap-changeset#',
doap => 'http://usefulinc.com/ns/doap#',
foaf => 'http://xmlns.com/foaf/0.1/',
rdfs => 'http://www.w3.org/2000/01/rdf-schema#',
});
open my $fh, '>', $out;
$rdfxml->serialize_model_to_file($fh, $changeset->{'model'});
close $fh;
}
1;
|