Commit 543b86f7 authored by Nicholas Bamber's avatar Nicholas Bamber

Imported Upstream version 0.1

parents
use 5.006;
use strict;
use warnings;
use Module::Build;
my $builder = Module::Build->new(
module_name => 'Debian::Copyright',
license => 'gpl',
dist_author => q{Nicholas Bamber <nicholas@periapt.co.uk>},
dist_version_from => 'lib/Debian/Copyright.pm',
build_requires => {
'Test::More' => 0,
'Perl6::Slurp' => 0,
'Test::LongString' => 0,
},
configure_requires => { 'Module::Build' => 0.38 },
requires => {
'perl' => 5.006,
'Parse::DebControl' => 0,
'Tie::IxHash' => 0,
'Array::Unique' => 0,
'Class::Accessor'=> 0,
},
add_to_cleanup => [ 'Debian-Copyright-*' ],
create_makefile_pl => 'traditional',
create_readme => 1,
meta_merge => {
resources => {
repository =>
'http://github.com/periapt/Debian-Copyright/tree',
},
},
);
$builder->create_build_script();
Revision history for Debian-Copyright
0.1 Date/time
First version, released on an unsuspecting world.
Build.PL
Changes
ignore.txt
lib/Debian/Copyright.pm
lib/Debian/Copyright/Stanza.pm
lib/Debian/Copyright/Stanza/Files.pm
lib/Debian/Copyright/Stanza/Header.pm
lib/Debian/Copyright/Stanza/License.pm
lib/Debian/Copyright/Stanza/OrSeparated.pm
Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
META.json
META.yml
README
t/00.load.t
t/01.basic.t
t/data/add1
t/data/copyright
t/manifest.t
t/perlcritic.t
t/pod-coverage.t
t/pod.t
t/podspell.t
t/prereq.t
t/version.t
#!start included /usr/share/perl/5.12/ExtUtils/MANIFEST.SKIP
# Avoid version control files.
\bRCS\b
\bCVS\b
\bSCCS\b
,v$
\B\.svn\b
\B\.git\b
\B\.gitignore\b
\b_darcs\b
\B\.cvsignore$
# Avoid VMS specific MakeMaker generated files
\bDescrip.MMS$
\bDESCRIP.MMS$
\bdescrip.mms$
# Avoid Makemaker generated and utility files.
\bMANIFEST\.bak
\bMakefile$
\bblib/
\bMakeMaker-\d
\bpm_to_blib\.ts$
\bpm_to_blib$
\bblibdirs\.ts$ # 6.18 through 6.25 generated this
# Avoid Module::Build generated and utility files.
\bBuild$
\b_build/
\bBuild.bat$
\bBuild.COM$
\bBUILD.COM$
\bbuild.com$
# Avoid temp and backup files.
~$
\.old$
\#$
\b\.#
\.bak$
\.tmp$
\.#
\.rej$
# Avoid OS-specific files/dirs
# Mac OSX metadata
\B\.DS_Store
# Mac OSX SMB mount metadata files
\B\._
# Avoid Devel::Cover files.
\bcover_db\b
#!end included /usr/share/perl/5.12/ExtUtils/MANIFEST.SKIP
# Avoid configuration metadata file
^MYMETA\.
# Avoid Module::Build generated and utility files.
\bBuild$
\bBuild.bat$
\b_build
\bBuild.COM$
\bBUILD.COM$
\bbuild.com$
# Avoid archives of this distribution
\bDebian-Copyright-[\d\.\_]+
{
"abstract" : "manage Debian copyright files",
"author" : [
"Nicholas Bamber <nicholas@periapt.co.uk>"
],
"dynamic_config" : 1,
"generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.110930",
"license" : [
"open_source"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Debian-Copyright",
"prereqs" : {
"build" : {
"requires" : {
"Perl6::Slurp" : 0,
"Test::LongString" : 0,
"Test::More" : 0
}
},
"configure" : {
"requires" : {
"Module::Build" : "0.38"
}
},
"runtime" : {
"requires" : {
"Array::Unique" : 0,
"Class::Accessor" : 0,
"Parse::DebControl" : 0,
"Tie::IxHash" : 0,
"perl" : "5.006"
}
}
},
"provides" : {
"Debian::Copyright" : {
"file" : "lib/Debian/Copyright.pm",
"version" : "0.1"
},
"Debian::Copyright::Stanza" : {
"file" : "lib/Debian/Copyright/Stanza.pm",
"version" : "0.1"
},
"Debian::Copyright::Stanza::Files" : {
"file" : "lib/Debian/Copyright/Stanza/Files.pm",
"version" : "0.1"
},
"Debian::Copyright::Stanza::Header" : {
"file" : "lib/Debian/Copyright/Stanza/Header.pm",
"version" : "0.1"
},
"Debian::Copyright::Stanza::License" : {
"file" : "lib/Debian/Copyright/Stanza/License.pm",
"version" : "0.1"
},
"Debian::Copyright::Stanza::OrSeparated" : {
"file" : "lib/Debian/Copyright/Stanza/OrSeparated.pm",
"version" : "0.1"
}
},
"release_status" : "stable",
"resources" : {
"license" : [
"http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt"
],
"repository" : {
"url" : "http://github.com/periapt/Debian-Copyright/tree"
}
},
"version" : "0.1"
}
---
abstract: 'manage Debian copyright files'
author:
- 'Nicholas Bamber <nicholas@periapt.co.uk>'
build_requires:
Perl6::Slurp: 0
Test::LongString: 0
Test::More: 0
configure_requires:
Module::Build: 0.38
dynamic_config: 1
generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.110930'
license: open_source
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Debian-Copyright
provides:
Debian::Copyright:
file: lib/Debian/Copyright.pm
version: 0.1
Debian::Copyright::Stanza:
file: lib/Debian/Copyright/Stanza.pm
version: 0.1
Debian::Copyright::Stanza::Files:
file: lib/Debian/Copyright/Stanza/Files.pm
version: 0.1
Debian::Copyright::Stanza::Header:
file: lib/Debian/Copyright/Stanza/Header.pm
version: 0.1
Debian::Copyright::Stanza::License:
file: lib/Debian/Copyright/Stanza/License.pm
version: 0.1
Debian::Copyright::Stanza::OrSeparated:
file: lib/Debian/Copyright/Stanza/OrSeparated.pm
version: 0.1
requires:
Array::Unique: 0
Class::Accessor: 0
Parse::DebControl: 0
Tie::IxHash: 0
perl: 5.006
resources:
license: http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt
repository: http://github.com/periapt/Debian-Copyright/tree
version: 0.1
# Note: this file was auto-generated by Module::Build::Compat version 0.3800
require 5.006;
use ExtUtils::MakeMaker;
WriteMakefile
(
'NAME' => 'Debian::Copyright',
'VERSION_FROM' => 'lib/Debian/Copyright.pm',
'PREREQ_PM' => {
'Array::Unique' => 0,
'Class::Accessor' => 0,
'Parse::DebControl' => 0,
'Perl6::Slurp' => 0,
'Test::LongString' => 0,
'Test::More' => 0,
'Tie::IxHash' => 0
},
'INSTALLDIRS' => 'site',
'EXE_FILES' => [],
'PL_FILES' => {}
)
;
NAME
Debian::Copyright - manage Debian copyright files
VERSION
This document describes Debian::Copyright version 0.1 .
SYNOPSIS
my $c = Debian::Copyright->new(); # construct a new
$c->read($file1); # parse debian copyright file
$c->read($file2); # parse a second
$c->write($ofile); # write to file
DESCRIPTION
Debian::Copyright can be used for the representation, manipulation and
merging of Debian copyright files in an object-oriented way. It provides
easy reading and writing of the debian/copyright file found in Debian
source packages.
FIELDS
header
An instance of Debian::Copyright::Stanza::Header class. Contains the the
first stanza of the copyright file. If multiple files were parsed only
the first will be retained.
files
A hash reference (actually Tie::IxHash instance) with keys being the
values of the `Files' clause and values instances of
Debian::Copyright::Stanza::Files class.
licenses
A hash reference (actually Tie::IxHash instance) with keys being the
values of the `License' clause and values instances of
Debian::Copyright::Stanza::License class.
CONSTRUCTOR
new
Constructs a new Debian::Copyright instance.
The `header' field is initialised with an empty string. The
`files_block' and `license_block' fields are initialised with an empty
instance of Tie::IxHash.
METHODS
read *file*
Parse debian and accessors.
*file* can be either a file name, an opened file handle or a string
scalar reference.
write *file*
Writes a debian/copyright-like file in *file* with the contents defined
in the accessor fields.
*file* can be either a file name, an opened file handle or a string
scalar reference.
LIMITATIONS
This module is written with one particular version of DEP-5 in mind.
When required it should be easy to add support for extra versions, but
at the moment the supported version is the one generally used in the
Debian Perl Group.
Test coverage is not yet complete.
COPYRIGHT & LICENSE
Copyright (C) 2011 Nicholas Bamber nicholas@periapt.co.uk
This module was adapted from Debian::Control. Copyright (C) 2009 Damyan
Ivanov dmn@debian.org [Portions]
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as published
by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
blib*
Makefile
Makefile.old
Build
Build.bat
_build*
pm_to_blib*
*.tar.gz
.lwpcookies
cover_db
pod2htm*.tmp
Debian-Copyright-*
=head1 NAME
Debian::Copyright - manage Debian copyright files
=head1 VERSION
This document describes Debian::Copyright version 0.1 .
=head1 SYNOPSIS
my $c = Debian::Copyright->new(); # construct a new
$c->read($file1); # parse debian copyright file
$c->read($file2); # parse a second
$c->write($ofile); # write to file
=head1 DESCRIPTION
Debian::Copyright can be used for the representation, manipulation and
merging of Debian copyright files in an object-oriented way. It provides easy
reading and writing of the F<debian/copyright> file found in Debian source
packages.
=head1 FIELDS
=head2 header
An instance of L<Debian::Copyright::Stanza::Header> class. Contains the
the first stanza of the copyright file. If multiple files were parsed only the
first will be retained.
=head2 files
A hash reference (actually L<Tie::IxHash> instance) with keys being the values
of the C<Files> clause and values instances of
L<Debian::Copyright::Stanza::Files> class.
=head2 licenses
A hash reference (actually L<Tie::IxHash> instance) with keys being the values
of the C<License> clause and values instances of
L<Debian::Copyright::Stanza::License> class.
=cut
package Debian::Copyright;
use base 'Class::Accessor';
use strict;
use Carp;
our $VERSION = '0.1';
__PACKAGE__->mk_accessors(qw( _parser header files licenses ));
use Parse::DebControl;
use Debian::Copyright::Stanza::Header;
use Debian::Copyright::Stanza::Files;
use Debian::Copyright::Stanza::License;
use Tie::IxHash;
=head1 CONSTRUCTOR
=head2 new
Constructs a new L<Debian::Copyright> instance.
The C<header> field is initialised with an empty string.
The C<files_block> and C<license_block> fields are initialised with an
empty instance of L<Tie::IxHash>.
=cut
sub new {
my $class = shift;
my $self = $class->SUPER::new();
$self->_parser( Parse::DebControl->new );
$self->header(undef);
$self->files( Tie::IxHash->new );
$self->licenses( Tie::IxHash->new );
return $self;
}
=head1 METHODS
=head2 read I<file>
Parse L<debian/copyright> and accessors.
I<file> can be either a file name, an opened file handle or a string scalar
reference.
=cut
sub read {
my ( $self, $file ) = @_;
my $parser_method = 'parse_file';
if ( ref($file) ) {
$file = $$file;
$parser_method = 'parse_mem';
}
my $stanzas = $self->_parser->$parser_method( $file,
{ useTieIxHash => 1, verbMultiLine => 1 } );
for (@$stanzas) {
if ( $_->{'Format-Specification'}) {
if (! $self->header) {
$self->header( Debian::Copyright::Stanza::Header->new($_) );
}
}
elsif ( $_->{Files} ) {
$self->files->Push(
$_->{Files} => Debian::Copyright::Stanza::Files->new($_) );
}
elsif ( $_->{License} ) {
my $license = $_->{License};
if ($license =~ m{\A([^\n]+)$}xms) {
$license = $1;
}
else {
croak "License stanza does not make sense";
}
$self->licenses->Push(
$license => Debian::Copyright::Stanza::License->new($_) );
}
else {
die "Got copyright stanza with unrecognised field\n";
}
}
return;
}
=head2 write I<file>
Writes a debian/copyright-like file in I<file> with the contents defined in the
accessor fields.
I<file> can be either a file name, an opened file handle or a string scalar
reference.
=cut
sub write {
my ( $self, $file ) = @_;
my @stanzas = (
$self->header,
$self->files->Values,
$self->licenses->Values
);
my $string = join "\n", @stanzas;
if ( ref($file) and ref($file) eq 'SCALAR' ) {
$$file = $string;
}
elsif ( ref($file) and ref($file) eq 'GLOB' ) {
$file->print($string);
}
else {
my $fh;
open $fh, '>', $file or die "Unable to open '$file' for writing: $!";
print $fh $string;
}
}
=head1 LIMITATIONS
=over
=item This module is written with one particular version of
L<DEP-5|http://anonscm.debian.org/viewvc/dep/web/deps/dep5.mdwn?view=markup&pathrev=135>
in mind. When required it should be easy to add support for extra versions,
but at the moment the supported version is the one generally used in the
Debian Perl Group.
=item Test coverage is not yet complete.
=back
=head1 COPYRIGHT & LICENSE
Copyright (C) 2011 Nicholas Bamber L<nicholas@periapt.co.uk>
This module was adapted from L<Debian::Control>.
Copyright (C) 2009 Damyan Ivanov L<dmn@debian.org> [Portions]
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License version 2 as published by the Free
Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
=cut
1;
=head1 NAME
Debian::Copyright::Stanza - single stanza of Debian copyright file
=head1 VERSION
This document describes Debian::Copyright::Stanza version 0.1 .
=head1 SYNOPSIS
package Header;
use base 'Debian::Copyright::Stanza';
use constant fields => qw(
Format_Specification
Name
Source
Maintainer
X_Comment
);
1;
=head1 DESCRIPTION
Debian::Copyright::Stanza is the base class for
L<Debian::Copyright::Stanza::Header>, L<Debian::Copyright::Stanza::Files> and
L<Debian::Copyright::Stanza::License> classes.
=cut
package Debian::Copyright::Stanza;
require v5.10.0;
use strict;
use base qw( Class::Accessor Tie::IxHash );
use Carp qw(croak);
use Debian::Copyright::Stanza::OrSeparated;
our $VERSION = '0.1';
=head1 FIELDS
Stanza fields are to be defined in the class method I<fields>. Typically this
can be done like:
use constant fields => qw( Foo Bar Baz );
Fields that are to contain dependency lists (as per L</is_dependency_list>
method below) are automatically converted to instances of the
L<Debian::Dependencies> class.
=cut
use constant fields => ();
sub import {
my( $class ) = @_;
$class->mk_accessors( $class->fields );
}
use overload '""' => \&as_string;
=head1 CONSTRUCTOR
=head2 new( { field => value, ... } )
Creates a new L<Debian::Copyright::Stanza> object and optionally initialises it
with the supplied data. The object is hashref based and tied to L<Tie::IxHash>.
You may use dashes for initial field names, but these will be converted to
underscores:
my $s = Debian::Copyright::Stanza::Header( {Name => "Blah"} );
print $s->Name;
=cut
sub new {
my $class = shift;
my $init = shift || {};
my $self = Tie::IxHash->new;
bless $self, $class;
while( my($k,$v) = each %$init ) {
$k =~ s/-/_/g;
$self->can($k)
or croak "Invalid field given ($k)";
if ( $self->is_or_separated($k) ) {
$self->$k( Debian::Copyright::Stanza::OrSeparated->new( $v ) );
}
else {
$self->$k($v);
}
}
return $self;
}
=head1 METHODS
=head2 is_or_separated($field)
Returns true if the given field is to contain a 'or'-separated list of values.
This is used in stringification, when considering where to wrap long lines.
=cut
sub is_or_separated {
my( $self, $field ) = @_;
return 0;
}
=head2 get($field)
Overrides the default get method from L<Class::Accessor> with L<Tie::IxHash>'s
FETCH.
=cut
sub get {
my( $self, $field ) = @_;
$field =~ s/_/-/g;
return $self->FETCH($field);
}
=head2 set( $field, $value )
Overrides the default set method from L<Class::Accessor> with L<Tie::IxHash>'s
STORE.
=cut
sub set {
my( $self, $field, $value ) = @_;
chomp($value);
$field =~ s/_/-/g;
return $self->STORE( $field, $value );
}
=head2 as_string([$width])
Returns a string representation of the object. Ready to be printed into a
real F<debian/copyright> file. Used as a stringification operator.
=cut
sub as_string
{
my ( $self, $width ) = @_;
$width //= 80;
my @lines;
$self->Reorder( map{ ( my $s = $_ ) =~ s/_/-/g; $s } $self->fields );
for my $k ( $self->Keys ) {
# We don't' want the internal fields showing in the output
next if $k =~ /^-/; # _ in field names is replaced with dashes
my $v = $self->FETCH($k);
next unless defined($v);
my $line = "$k: $v";
push @lines, $line if $line;
}
return join( "\n", @lines ) . "\n";
}
=head1 COPYRIGHT & LICENSE
Copyright (C) 2011 Nicholas Bamber <nicholas@periapt.co.uk>
This module is substantially based upon L<Debian::Control::Stanza>.