Commit c59dbaeb authored by Xavier Guimard's avatar Xavier Guimard

Merge tag 'upstream/0.2'

Upstream version 0.2
parents 00cb0585 a8f4f93e
......@@ -12,6 +12,9 @@ my $builder = Module::Build->new(
'Test::More' => 0,
'Perl6::Slurp' => 0,
'Test::LongString' => 0,
'Test::Exception' => 0,
'Test::Deep' => 0,
'Test::NoWarnings' => 0,
},
configure_requires => { 'Module::Build' => 0.38 },
requires => {
......@@ -20,6 +23,7 @@ my $builder = Module::Build->new(
'Tie::IxHash' => 0,
'Array::Unique' => 0,
'Class::Accessor'=> 0,
perl=>'5.10.1',
},
add_to_cleanup => [ 'Debian-Copyright-*' ],
create_makefile_pl => 'traditional',
......
Revision history for Debian-Copyright
0.1 Date/time
0.2 23-07-2012
Added support for full bodies that occur in License
clauses in Files stanzas
Added some real life copyright tests from mysql
Used comments from Charles Plessy, Closes: #70544
Worked through some of the missing test coverage
Updated copyright notices
0.1 12-08-2011
First version, released on an unsuspecting world.
......@@ -15,8 +15,12 @@ META.yml
README
t/00.load.t
t/01.basic.t
t/02.mysql.t
t/data/add1
t/data/copyright
t/data/invalid
t/data/invalid2
t/data/mysql
t/manifest.t
t/perlcritic.t
t/pod-coverage.t
......
......@@ -4,9 +4,9 @@
"Nicholas Bamber <nicholas@periapt.co.uk>"
],
"dynamic_config" : 1,
"generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.110930",
"generated_by" : "Module::Build version 0.4001, CPAN::Meta::Converter version 2.110440",
"license" : [
"open_source"
"gpl_1"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
......@@ -17,8 +17,11 @@
"build" : {
"requires" : {
"Perl6::Slurp" : 0,
"Test::Deep" : 0,
"Test::Exception" : 0,
"Test::LongString" : 0,
"Test::More" : 0
"Test::More" : 0,
"Test::NoWarnings" : 0
}
},
"configure" : {
......@@ -32,34 +35,34 @@
"Class::Accessor" : 0,
"Parse::DebControl" : 0,
"Tie::IxHash" : 0,
"perl" : "5.006"
"perl" : "v5.10.1"
}
}
},
"provides" : {
"Debian::Copyright" : {
"file" : "lib/Debian/Copyright.pm",
"version" : "0.1"
"version" : "0.2"
},
"Debian::Copyright::Stanza" : {
"file" : "lib/Debian/Copyright/Stanza.pm",
"version" : "0.1"
"version" : "0.2"
},
"Debian::Copyright::Stanza::Files" : {
"file" : "lib/Debian/Copyright/Stanza/Files.pm",
"version" : "0.1"
"version" : "0.2"
},
"Debian::Copyright::Stanza::Header" : {
"file" : "lib/Debian/Copyright/Stanza/Header.pm",
"version" : "0.1"
"version" : "0.2"
},
"Debian::Copyright::Stanza::License" : {
"file" : "lib/Debian/Copyright/Stanza/License.pm",
"version" : "0.1"
"version" : "0.2"
},
"Debian::Copyright::Stanza::OrSeparated" : {
"file" : "lib/Debian/Copyright/Stanza/OrSeparated.pm",
"version" : "0.1"
"version" : "0.2"
}
},
"release_status" : "stable",
......@@ -71,5 +74,5 @@
"url" : "http://github.com/periapt/Debian-Copyright/tree"
}
},
"version" : "0.1"
"version" : "0.2"
}
......@@ -4,13 +4,16 @@ author:
- 'Nicholas Bamber <nicholas@periapt.co.uk>'
build_requires:
Perl6::Slurp: 0
Test::Deep: 0
Test::Exception: 0
Test::LongString: 0
Test::More: 0
Test::NoWarnings: 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
generated_by: 'Module::Build version 0.4001, CPAN::Meta::Converter version 2.110440'
license: gpl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
......@@ -18,29 +21,29 @@ name: Debian-Copyright
provides:
Debian::Copyright:
file: lib/Debian/Copyright.pm
version: 0.1
version: 0.2
Debian::Copyright::Stanza:
file: lib/Debian/Copyright/Stanza.pm
version: 0.1
version: 0.2
Debian::Copyright::Stanza::Files:
file: lib/Debian/Copyright/Stanza/Files.pm
version: 0.1
version: 0.2
Debian::Copyright::Stanza::Header:
file: lib/Debian/Copyright/Stanza/Header.pm
version: 0.1
version: 0.2
Debian::Copyright::Stanza::License:
file: lib/Debian/Copyright/Stanza/License.pm
version: 0.1
version: 0.2
Debian::Copyright::Stanza::OrSeparated:
file: lib/Debian/Copyright/Stanza/OrSeparated.pm
version: 0.1
version: 0.2
requires:
Array::Unique: 0
Class::Accessor: 0
Parse::DebControl: 0
Tie::IxHash: 0
perl: 5.006
perl: v5.10.1
resources:
license: http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt
repository: http://github.com/periapt/Debian-Copyright/tree
version: 0.1
version: 0.2
# Note: this file was auto-generated by Module::Build::Compat version 0.3800
require 5.006;
# Note: this file was auto-generated by Module::Build::Compat version 0.4001
require 5.010001;
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',
'VERSION_FROM' => 'lib/Debian/Copyright.pm',
'PREREQ_PM' => {
'Array::Unique' => 0,
'Class::Accessor' => 0,
'Parse::DebControl' => 0,
'Perl6::Slurp' => 0,
'Test::Deep' => 0,
'Test::Exception' => 0,
'Test::LongString' => 0,
'Test::More' => 0,
'Test::NoWarnings' => 0,
'Tie::IxHash' => 0
},
'INSTALLDIRS' => 'site',
'EXE_FILES' => [],
'PL_FILES' => {}
)
;
......@@ -2,19 +2,27 @@ NAME
Debian::Copyright - manage Debian copyright files
VERSION
This document describes Debian::Copyright version 0.1 .
This document describes Debian::Copyright version 0.2 .
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
$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.
source packages. Debian has recently started standardising its copyright
files around the machine-readable DEP-5/Format:
http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
format.
note on terminology
The term "Stanza" derives from the dh-make-perl tool. The official term
would now be "Paragraph". For the purposes of discussing the DEP-5
format the terms are used interchangeably in this documentation.
FIELDS
header
......@@ -56,13 +64,20 @@ METHODS
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.
Furthermore version 0.1 of this software was for a draft version the
standard. The changes in going from draft to standard were such that it
was not worth attempting to maintain backwards compatibility.
Test coverage is not yet complete.
INCOMPATIBILITIES
This version is not backwards compatible with version 0.1.
ACKNOWLEDGEMENTS
Thanks to Charles Plessy for various comments regarding the
documentation.
COPYRIGHT & LICENSE
Copyright (C) 2011 Nicholas Bamber nicholas@periapt.co.uk
Copyright (C) 2011-2012 Nicholas Bamber nicholas@periapt.co.uk
This module was adapted from Debian::Control. Copyright (C) 2009 Damyan
Ivanov dmn@debian.org [Portions]
......
......@@ -4,21 +4,30 @@ Debian::Copyright - manage Debian copyright files
=head1 VERSION
This document describes Debian::Copyright version 0.1 .
This document describes Debian::Copyright version 0.2 .
=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
$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.
packages. Debian has recently started standardising its copyright files
around the machine-readable
L<DEP-5/Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/>
format.
=head2 note on terminology
The term "Stanza" derives from the
L<dh-make-perl|http://packages.debian.org/sid/dh-make-perl> tool. The official
term would now be "Paragraph". For the purposes of discussing the DEP-5 format the terms are used interchangeably in this documentation.
=head1 FIELDS
......@@ -43,11 +52,12 @@ L<Debian::Copyright::Stanza::License> class.
=cut
package Debian::Copyright;
require v5.10.1;
use base 'Class::Accessor';
use strict;
use Carp;
our $VERSION = '0.1';
our $VERSION = '0.2';
__PACKAGE__->mk_accessors(qw( _parser header files licenses ));
......@@ -107,17 +117,21 @@ sub read {
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($_) );
}
if (exists $stanzas->[0]->{Format}) {
my $header = shift @$stanzas;
if (! $self->header) {
$self->header( Debian::Copyright::Stanza::Header->new($header) );
}
elsif ( $_->{Files} ) {
}
for (@$stanzas) {
next if $_->{Format};
if ( $_->{Files} ) {
$self->files->Push(
$_->{Files} => Debian::Copyright::Stanza::Files->new($_) );
next;
}
elsif ( $_->{License} ) {
if ( $_->{License} ) {
my $license = $_->{License};
if ($license =~ m{\A([^\n]+)$}xms) {
$license = $1;
......@@ -127,10 +141,9 @@ sub read {
}
$self->licenses->Push(
$license => Debian::Copyright::Stanza::License->new($_) );
next;
}
else {
die "Got copyright stanza with unrecognised field\n";
}
die "Got copyright stanza with unrecognised field\n";
}
return;
}
......@@ -174,18 +187,27 @@ sub write {
=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.
L<DEP-5|http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/>
in mind. Furthermore version 0.1 of this software was for a draft
version the standard. The changes in going from draft to standard
were such that it was not worth attempting to maintain backwards
compatibility.
=item Test coverage is not yet complete.
=back
=head1 INCOMPATIBILITIES
This version is not backwards compatible with version 0.1.
=head1 ACKNOWLEDGEMENTS
Thanks to Charles Plessy for various comments regarding the documentation.
=head1 COPYRIGHT & LICENSE
Copyright (C) 2011 Nicholas Bamber L<nicholas@periapt.co.uk>
Copyright (C) 2011-2012 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]
......
......@@ -4,7 +4,7 @@ Debian::Copyright::Stanza - single stanza of Debian copyright file
=head1 VERSION
This document describes Debian::Copyright::Stanza version 0.1 .
This document describes Debian::Copyright::Stanza version 0.2 .
=head1 SYNOPSIS
......@@ -30,13 +30,13 @@ L<Debian::Copyright::Stanza::License> classes.
package Debian::Copyright::Stanza;
require v5.10.0;
require v5.10.1;
use strict;
use base qw( Class::Accessor Tie::IxHash );
use Carp qw(croak);
use Debian::Copyright::Stanza::OrSeparated;
our $VERSION = '0.1';
our $VERSION = '0.2';
=head1 FIELDS
......
......@@ -4,7 +4,7 @@ Debian::Copyright::Stanza::Files - Files stanza of Debian copyright file
=head1 VERSION
This document describes Debian::Copyright::Stanza::Files version 0.1 .
This document describes Debian::Copyright::Stanza::Files version 0.2 .
=head1 SYNOPSIS
......@@ -33,21 +33,22 @@ replaced with underscores.
=item Copyright
=item X_Comment
=item Comment
=back
=cut
package Debian::Copyright::Stanza::Files;
require v5.10.1;
use strict;
use warnings;
use base qw(Debian::Copyright::Stanza);
use constant fields => qw (
Files Copyright License X_Comment
Files Copyright License Comment
);
our $VERSION = '0.1';
our $VERSION = '0.2';
=head1 CONSTRUCTOR
......@@ -77,7 +78,7 @@ L<Debian::Copyright::Stanza>
=head1 COPYRIGHT & LICENSE
Copyright (C) 2011 Nicholas Bamber L<nicholas@periapt.co.uk>
Copyright (C) 2011-12 Nicholas Bamber L<nicholas@periapt.co.uk>
This module is substantially based upon L<Debian::Control::Stanza::Source>.
Copyright (C) 2009 Damyan Ivanov L<dmn@debian.org>
......
......@@ -4,7 +4,7 @@ Debian::Copyright::Stanza::Header - header stanza of Debian copyright file
=head1 VERSION
This document describes Debian::Copyright::Stanza::Header version 0.1 .
This document describes Debian::Copyright::Stanza::Header version 0.2 .
=head1 SYNOPSIS
......@@ -27,29 +27,44 @@ replaced with underscores.
=over
=item Format_Specification
=item Format
=item Name
=item Upstream_Name
=item X_Comment
=item Comment
=item Maintainer
=item Upstream_Contact
=item Source
=item Disclaimer
=item License
=item Copyright
=back
=cut
package Debian::Copyright::Stanza::Header;
require v5.10.1;
use strict;
use warnings;
use base qw(Debian::Copyright::Stanza);
use constant fields => qw (
Format_Specification Maintainer Source Name X_Comment
Format
Upstream_Name
Upstream_Contact
Source
Disclaimer
Comment
License
Copyright
);
our $VERSION = '0.1';
our $VERSION = '0.2';
=head1 CONSTRUCTOR
......@@ -71,7 +86,7 @@ L<Debian::Copyright::Stanza>
=head1 COPYRIGHT & LICENSE
Copyright (C) 2011 Nicholas Bamber L<nicholas@periapt.co.uk>
Copyright (C) 2011-12 Nicholas Bamber L<nicholas@periapt.co.uk>
This module is substantially based upon L<Debian::Control::Stanza::Source>.
Copyright (C) 2009 Damyan Ivanov L<dmn@debian.org>
......
......@@ -4,7 +4,7 @@ Debian::Copyright::Stanza::License - License stanza of Debian copyright file
=head1 VERSION
This document describes Debian::Copyright::Stanza::License version 0.1 .
This document describes Debian::Copyright::Stanza::License version 0.2 .
=head1 SYNOPSIS
......@@ -29,19 +29,22 @@ replaced with underscores.
=item License
=item Comment
=back
=cut
package Debian::Copyright::Stanza::License;
require v5.10.1;
use strict;
use warnings;
use base qw(Debian::Copyright::Stanza);
use constant fields => qw (
X_Comment License
License Comment
);
our $VERSION = '0.1';
our $VERSION = '0.2';
=head1 CONSTRUCTOR
......@@ -63,7 +66,7 @@ L<Debian::Copyright::Stanza>
=head1 COPYRIGHT & LICENSE
Copyright (C) 2011 Nicholas Bamber L<nicholas@periapt.co.uk>
Copyright (C) 2011-12 Nicholas Bamber L<nicholas@periapt.co.uk>
This module is substantially based upon L<Debian::Control::Stanza::Source>.
Copyright (C) 2009 Damyan Ivanov L<dmn@debian.org>
......
package Debian::Copyright::Stanza::OrSeparated;
require v5.10.1;
use strict;
use warnings;
......@@ -8,7 +9,7 @@ use overload
'""' => \&as_string,
'eq' => \&equals;
our $VERSION = '0.1';
our $VERSION = '0.2';
=head1 NAME
......@@ -16,7 +17,7 @@ Debian::Copyright::Stanza::OrSeparated - 'or' separated field abstraction
=head1 VERSION
This document describes Debian::Copyright::Stanza::OrSeparated version 0.1 .
This document describes Debian::Copyright::Stanza::OrSeparated version 0.2 .
=cut
......@@ -32,7 +33,8 @@ This document describes Debian::Copyright::Stanza::OrSeparated version 0.1 .
=head1 DESCRIPTION
Debian::Copyright::Stanza::OrSeparated abstracts handling of the License
fields in Files blocks, which are lists separated by 'or'.
fields in Files blocks, which are lists separated by 'or'. It also supports
a body field representing the optional extended description of a License field.
=head1 CONSTRUCTOR
......@@ -45,11 +47,23 @@ C<quotewords> routine.
=cut
sub new {
my $self = bless [], shift;
tie @$self, 'Array::Unique';
$self->add(@_) if @_;
my $self = bless {list=>[],body=>""}, shift;
tie @{$self->{list}}, 'Array::Unique';
my $body = exists $self->{body} ? $self->{body} : "";
my @list = ();
foreach my $e (@_) {
if ($e =~ m{\A([^\n]+)\n(.+)\z}xms) {
push @list, $1;
$body .= $2;
}
else {
push @list, $e;
}
}
$self->add(@list) if @list;
$self->{body} = $body if $body;
$self;
}
......@@ -66,7 +80,9 @@ operation.
sub as_string
{
return join( ' or ', @{ $_[0] } );
my $self = shift;
my $body = exists $self->{body} ? "\n$self->{body}" : "";
return join( ' or ', @{ $self->{list} } ).$body;
}
=head2 equals
......@@ -104,7 +120,7 @@ keeping the list unique.
sub add {
my ( $self, @items) = @_;
push @$self, $self->_parse(@items);
push @{$self->{list}}, $self->_parse(@items);
}
=head2 sort
......@@ -116,8 +132,23 @@ A handy method for sorting the list.
sub sort {
my $self = shift;
@$self = sort @$self;
@{$self->{list}} = sort @{$self->{list}};
}
=head1 COPYRIGHT & LICENSE
Copyright (C) 2011-12 Nicholas Bamber L<nicholas@periapt.co.uk>
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;
1;
use Test::More tests => 30;
use Test::More tests => 36;
use Debian::Copyright;
# replace by Test::File::Contents?
use Perl6::Slurp;
use Test::LongString;
use Test::Deep;
use Test::Exception;
my $copyright = Debian::Copyright->new;
isa_ok($copyright, 'Debian::Copyright');
$copyright->read('t/data/copyright');
like($copyright->header, qr{\AFormat-Specification:\s}xms, 'Header stanza');
like($copyright->header, qr{\AFormat:\s}xms, 'Header stanza');
is($copyright->files->Length, 2, 'files length');
is($copyright->files->Keys(0), '*', 'key files(0)');
is($copyright->files->Values(0)->Files, '*', 'files(0)->Files');
......@@ -33,6 +35,11 @@ my $data = undef;
$copyright->write(\$data);
is_string($data, $contents, "file contents");
my $copyright2 = Debian::Copyright->new;
isa_ok($copyright2, 'Debian::Copyright');
$copyright2->read(\$contents);
cmp_deeply($copyright, $copyright2, "file versus string");
$copyright->read('t/data/add1');
$copyright->write(\$data);
is($copyright->files->Length, 3, 'files length');
......@@ -56,4 +63,12 @@ is($copyright->files->Keys(2), 'test/*', 'key files(2)');
is($copyright->files->Values(2)->Files, 'test/*', 'files(2)->Files');
is($copyright->licenses->Keys(2), 'BSD', 'key licenses(2)');
my $copyright3 = Debian::Copyright->new;
isa_ok($copyright3, 'Debian::Copyright');
throws_ok { $copyright3->read('t/data/invalid') } qr/Invalid field given \(Blah\)/;
my $copyright4 = Debian::Copyright->new;
isa_ok($copyright4, 'Debian::Copyright');
throws_ok { $copyright4->read('t/data/invalid2') } qr/Got copyright stanza with unrecognised field/;
This diff is collapsed.
Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=136
Maintainer: Nicholas Bamber <nicholas@periapt.co.uk>
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Contact: Nicholas Bamber <nicholas@periapt.co.uk>
Upstream-Name: pkg-components
Source: http://github.com/periapt/pkg-components
Name: pkg-components
X-Comment: This is a test.
Files: test/*
......
Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135
Maintainer: Nicholas Bamber <nicholas@periapt.co.uk>
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: pkg-components
Upstream-Contact: Nicholas Bamber <nicholas@periapt.co.uk>
Source: http://github.com/periapt/pkg-components
Name: pkg-components
Files: *
Copyright:
......
Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135
Blah: Nicholas Bamber <nicholas@periapt.co.uk>
Blah2: http://github.com/periapt/pkg-components
Blah3: pkg-components
Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135
Upstream-Contact: Nicholas Bamber <nicholas@periapt.co.uk>
Source: http://github.com/periapt/pkg-components
Upstream-Name: pkg-components
Blah: *
Blah2: