r28057 - in /trunk/dh-make-perl/lib/Debian: Control.pm Control/ Control/FromCPAN.pm
dmn at users.alioth.debian.org
dmn at users.alioth.debian.org
Thu Dec 11 12:12:30 UTC 2008
Author: dmn
Date: Thu Dec 11 12:12:22 2008
New Revision: 28057
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=28057
Log:
add (unfinished, unused) Control classes
The purpose is to abstract handling of the debian/control file.
Say we package new perl module
my $c = Control::FromMeta->new_from_cpan_meta(YAML::LoadFile('META.yml'));
$c->write; # creates debian/control with dependencies etc
or, upgrade the package
my $c = Control::FromCPAN->new;
$c->read('debian/control'); # get present information
$c->fill_from_cpan_meta(YAML::LoadFile('META.yml')); # update deps etc
$c->write('debian/control'); # write updated file
Added:
trunk/dh-make-perl/lib/Debian/Control/
trunk/dh-make-perl/lib/Debian/Control.pm
trunk/dh-make-perl/lib/Debian/Control/FromCPAN.pm
Added: trunk/dh-make-perl/lib/Debian/Control.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/dh-make-perl/lib/Debian/Control.pm?rev=28057&op=file
==============================================================================
--- trunk/dh-make-perl/lib/Debian/Control.pm (added)
+++ trunk/dh-make-perl/lib/Debian/Control.pm Thu Dec 11 12:12:22 2008
@@ -1,0 +1,59 @@
+# The C<Control> class represent debian/control file of a single Debian
+# source package
+#
+# SYNOPSIS
+#
+# my $c = Control->read($file); # construct from file
+# my $c = Control->new(\%data); # construct anew with optional data
+# $c->write($file); # write to file
+# print $c->source->{Package};
+# print for @{ $c->source->{Build-Depends} }; # arrayref of Dep objects
+# $c->binary->{'libfoo-perl'}{Description} = "Foo Perl module\n"
+# . " Foo makes this and that";
+#
+package Debian::Control;
+
+use base 'Class::Accessor';
+
+__PACKAGE__->mk_accessors( qw( source binary _parser ) );
+
+use Parse::DebControl;
+
+sub new {
+ my $class = shift;
+
+ my $self = $class->SUPER::new(@_);
+
+ $self->_parser( Parse::DebControl->new );
+
+ $self->binary( {} );
+}
+
+sub read {
+ my ( $self, $file ) = @_;
+
+ my $stanzas = $self->_parser->parse_file( $file,
+ { useTieIxHash => 1, verbMultiLine => 1 } );
+
+ for (@$stanzas) {
+ if ( $_->{Source} ) {
+ $self->source($_);
+ }
+ elsif ( $_->{Package} ) {
+ $self->binary->{ $_->{Package} } = $_;
+ }
+ else {
+ die "Got control stanza with neither Source nor Package field\n";
+ }
+ }
+}
+
+sub write {
+ my ( $self, $file ) = @_;
+
+ $self->_parser->write_file( $file,
+ $self->source,
+ values %{ $self->binary } );
+}
+
+1;
Added: trunk/dh-make-perl/lib/Debian/Control/FromCPAN.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/dh-make-perl/lib/Debian/Control/FromCPAN.pm?rev=28057&op=file
==============================================================================
--- trunk/dh-make-perl/lib/Debian/Control/FromCPAN.pm (added)
+++ trunk/dh-make-perl/lib/Debian/Control/FromCPAN.pm Thu Dec 11 12:12:22 2008
@@ -1,0 +1,56 @@
+# C<Control::FromCPAN> adds ability to fill the control data from unpacked
+# CPAN distribution
+#
+# SYNOPSIS
+#
+# my $c = DhMakePerl::FromCPAN->new_from_cpan_meta( $meta, {opts} );
+# # construct from unpacked CPAN dist META.yml
+
+package Debian::Control::FromCPAN;
+
+use base 'Debian::Control';
+
+use YAML ();
+use File::Spec qw( catfile );
+
+sub new_from_cpan_meta {
+ my ( $class, $meta, $opts ) = @_;
+
+ my $self = $class->new;
+
+ $self->fill_from_cpan_meta( $meta, $opts );
+
+ return $self;
+}
+
+sub fill_from_cpan_meta {
+ my ( $self, $meta, $opts ) = @_;
+
+ my $name = $meta->{name};
+ defined($name)
+ or die "META.yml contains no distribution name or version";
+
+ $name = lc($name);
+ $name =~ s/::/-/g;
+ $name = "lib$name" unless $name =~ /^lib/;
+
+ $self->source( { Source => $name } );
+ my $src = $self->source;
+
+ $self->binary->{$name}{Package} = $name;
+ my $bin = $self->binary->{$name};
+
+ $self->description_from_meta($meta);
+ $self->dependencies_from_meta( $meta, $opts->{apt_contents} )
+ if $opts->{apt_contents};
+
+ $src->{Section} = $bin->{Section} = 'perl'
+ unless defined( $src->{Section} ) or defined( $bin->{Section} );
+ $src->{Priority} = $bin->{Priority} = 'optional'
+ unless defined( $src->{Priority} ) or defined( $bin->{Priority} );
+}
+
+
+1;
+
+
More information about the Pkg-perl-cvs-commits
mailing list