<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package DhMakePerl::Command::Packaging;

use strict;
use warnings;

our $VERSION = '0.77';

use feature 'switch';

=head1 NAME

DhMakePerl::Command::Packaging - common routines for 'make' and 'refresh' dh-make-perl commands

=cut

use base 'DhMakePerl';

__PACKAGE__-&gt;mk_accessors(
    qw( start_dir main_dir debian_dir
        mod_cpan_version
        meta perlname author
        version rules docs examples copyright
        control
    )
);

use Array::Unique;
use Carp qw(confess);
use CPAN ();
use CPAN::Meta;
use Cwd qw( getcwd );
use Debian::Control::FromCPAN;
use Debian::Dependencies;
use Debian::Rules;
use DhMakePerl::PodParser ();
use File::Basename qw(basename dirname);
use File::Find qw(find);
use File::Path ();
use File::Spec::Functions qw(catfile catpath splitpath);
use Parse::DebianChangelog;
use Text::Balanced qw(extract_quotelike);
use Text::Wrap qw(fill);
use User::pwent;

use constant debstdversion =&gt; '3.9.5';

our %DEFAULTS = (
    start_dir =&gt; getcwd(),
);

sub new {
    my $class = shift;
    $class = ref($class) if ref($class);

    my $self = $class-&gt;SUPER::new(@_);

    while( my( $k, $v ) = each %DEFAULTS ) {
        $self-&gt;$k($v) unless defined $self-&gt;$k;
    }

    $self-&gt;cfg or die "cfg is mandatory";

    my @docs;
    tie @docs, 'Array::Unique';

    $self-&gt;docs( \@docs );

    my @examples;
    tie @examples, 'Array::Unique';

    $self-&gt;examples( \@examples );

    $self-&gt;control( Debian::Control::FromCPAN-&gt;new )
        unless $self-&gt;control;

    return $self;
}

=head1 METHODS

=over

=item main_file(file_name)

Constructs a file name relative to the main source directory, L&lt;/main_dir&gt;

=cut

sub main_file {
    my( $self, $file ) = @_;

    catfile( $self-&gt;main_dir, $file );
}

=item debian_file(file_name)

Constructs a file name relative to the debian/ sub-directory of the main source
directory.

=cut

sub debian_file {
    my( $self, $file ) = @_;

    catfile( $self-&gt;main_file('debian'), $file );
}

sub build_pl {
    my ($self) = @_;

    return $self-&gt;main_file('Build.PL');
}

sub makefile_pl {
    my ($self) = @_;

    return $self-&gt;main_file('Makefile.PL');
}

sub get_developer {
    my $self = shift;

    my $email = $self-&gt;cfg-&gt;email;

    my ( $user, $pwnam, $name, $mailh );
    $user = $ENV{LOGNAME} || $ENV{USER};
    $pwnam = getpwuid($&lt;);
    die "Cannot determine current user\n" unless $pwnam;
    if ( defined $ENV{DEBFULLNAME} ) {
        $name = $ENV{DEBFULLNAME};
    }
    else {
        $name = $pwnam-&gt;gecos;
        $name =~ s/,.*//;
    }
    $user ||= $pwnam-&gt;name;
    $name ||= $user;
    $email ||= ( $ENV{DEBEMAIL} || $ENV{EMAIL} );
    unless ($email) {
        chomp( $mailh = `cat /etc/mailname` );
        $email = $user . '@' . $mailh;
    }

    $email =~ s/^(.*)\s+&lt;(.*)&gt;$/$2/;

    return "$name &lt;$email&gt;";
}

sub fill_maintainer {
    my $self = shift;

    my $src = $self-&gt;control-&gt;source;
    my $maint = $self-&gt;get_developer;

    if ( $self-&gt;cfg-&gt;pkg_perl ) {
        my $pkg_perl_maint
            = "Debian Perl Group &lt;pkg-perl-maintainers\@lists.alioth.debian.org&gt;";
        unless ( ( $src-&gt;Maintainer // '' ) eq $pkg_perl_maint ) {
            my $old_maint = $src-&gt;Maintainer;
            $src-&gt;Maintainer($pkg_perl_maint);
            $src-&gt;Uploaders-&gt;add($old_maint) if $old_maint;
        }

        $src-&gt;Uploaders-&gt;add($maint);
    }
    else {
        $src-&gt;Maintainer($maint);
    }
}

sub process_meta {
    my ($self) = @_;

    $self-&gt;meta({});

    # Command line option nometa causes this function not to be run
    if( $self-&gt;cfg-&gt;nometa ) {
        return;
    }

    my $meta = $self-&gt;main_file('META.json');
    if ( -e $meta ) {
        print "Using META.json\n" if $self-&gt;cfg-&gt;verbose;
    }
    else {
        $meta = $self-&gt;main_file('META.yml');
        if ( -e $meta ) {
            print "Using META.yml\n" if $self-&gt;cfg-&gt;verbose;
        }
        else {
            print "WARNING: Neither META.json nor META.yml was found\n";
            return;
        }
    }

    $meta = CPAN::Meta-&gt;load_file($meta);
    $self-&gt;meta( $meta-&gt;as_struct );
}

sub set_package_name {
    my $self = shift;

    my $pkgname;
    if (defined $self-&gt;cfg-&gt;packagename) {
      $pkgname = $self-&gt;cfg-&gt;packagename;
    }
    else {
        $pkgname = Debian::Control::FromCPAN-&gt;module_name_to_pkg_name( $self-&gt;perlname );
    }

    $self-&gt;control-&gt;source-&gt;Source($pkgname)
        unless $self-&gt;control-&gt;source-&gt;Source;

    $self-&gt;control-&gt;binary_tie-&gt;Push( $pkgname =&gt;
            Debian::Control::Stanza::Binary-&gt;new( { Package =&gt; $pkgname } ) )
        unless $self-&gt;control-&gt;binary-&gt;{$pkgname};
}

sub pkgname {
    @_ == 1 or die 'Syntax: $obj-&gt;pkgname()';

    my $self = shift;

    my $pkg = $self-&gt;control-&gt;binary_tie-&gt;Values(0)-&gt;Package;

    defined($pkg) and $pkg ne ''
        or confess "called before set_package_name()";

    return $pkg;
}

sub srcname {
    @_ == 1 or die 'Syntax: $obj-&gt;srcname()';

    my $self = shift;

    my $pkg = $self-&gt;control-&gt;source-&gt;Source;

    defined($pkg) and $pkg ne ''
        or confess "called before set_package_name()";

    return $pkg;
}

sub get_wnpp {
    my ( $self, $package ) = @_;

    return undef unless $self-&gt;cfg-&gt;network;

    my $wnpp = Debian::WNPP::Query-&gt;new(
        { cache_file =&gt; catfile( $self-&gt;cfg-&gt;home_dir, 'wnpp.cache' ) } );
    my @bugs = $wnpp-&gt;bugs_for_package($package);
    return $bugs[0];
}

sub extract_basic {
    my ($self) = @_;

    $self-&gt;extract_name_ver();

    my $src = $self-&gt;control-&gt;source;
    my $bin = $self-&gt;control-&gt;binary_tie-&gt;Values(0);

    $src-&gt;Section('perl') unless defined $src-&gt;Section;
    $src-&gt;Priority('optional') unless defined $src-&gt;Priority;

    if ( $self-&gt;cfg-&gt;arch ) {
        printf "Forcing architecture to '%s'\n", $self-&gt;cfg-&gt;arch;
        $bin-&gt;Architecture( $self-&gt;cfg-&gt;arch );
    }
    else {
        $bin-&gt;Architecture('all');
        find( sub { $self-&gt;check_for_xs }, $self-&gt;main_dir );
    }

    $self-&gt;cfg-&gt;dh('9')
        if $bin-&gt;Architecture eq 'any'
        and not $self-&gt;cfg-&gt;_explicitly_set-&gt;{dh};

    printf(
        "Found: %s %s (%s arch=%s)\n",
        $self-&gt;perlname, $self-&gt;version,
        $self-&gt;pkgname,  $bin-&gt;Architecture
    ) if $self-&gt;cfg-&gt;verbose;
    $self-&gt;debian_dir( $self-&gt;main_file('debian') );

    find(
        {   no_chdir =&gt; 1,
            wanted   =&gt; sub {
                return if $File::Find::name =~ $self-&gt;cfg-&gt;exclude;

                if (/\.(pm|pod)$/) {
                    $self-&gt;extract_desc($_)
                        unless $bin-&gt;short_description
                            and $bin-&gt;long_description;
                    $self-&gt;extract_basic_copyright($_)
                        unless $self-&gt;author and $self-&gt;copyright;
                }
            },
        },
        $self-&gt;main_dir
    );
}

sub sanitize_version {
    my $self = shift;
    my ($ver) = @_;

    return undef unless defined($ver);

    $ver =~ s/^v//;
    $ver =~ s/[^-.+a-zA-Z0-9]+/-/g;
    $ver = "0$ver" unless $ver =~ /^\d/;

    return $ver;
}

sub extract_name_ver {
    my ($self) = @_;

    my ( $name, $ver );

    if ( defined $self-&gt;meta-&gt;{name} and defined $self-&gt;meta-&gt;{version} ) {
        $name = $self-&gt;meta-&gt;{name};
        $ver  = $self-&gt;meta-&gt;{version};
    }
    elsif ( defined $self-&gt;cfg-&gt;packagename and defined $self-&gt;cfg-&gt;version ) {
        $name = $self-&gt;cfg-&gt;packagename;
        $ver  = $self-&gt;cfg-&gt;version;
    }
    else {
        if ( -e $self-&gt;build_pl ) {
            print "Extracting name and version from Build.PL\n";
            $self-&gt;extract_name_ver_from_build( $self-&gt;build_pl );
        }
        elsif ( -e $self-&gt;makefile_pl ) {
            print "Extracting name and version from Makefile.PL\n";
            $self-&gt;extract_name_ver_from_makefile( $self-&gt;makefile_pl );
        }
        else {
            if ( $self-&gt;cfg-&gt;cpan ) {
                my $name = $self-&gt;cfg-&gt;cpan;
                $name =~ s/::/-/g;
                $self-&gt;perlname($name);
            }
            else {
                die "Unable to determine dist name, no Build.PL, no Makefile.PL\nPlease use --cpan.\n";
            }
        }
        $name = $self-&gt;perlname;
        $ver  = $self-&gt;version;
    }

    $ver = $self-&gt;cfg-&gt;version
        if $self-&gt;cfg-&gt;version;

    defined($ver) and $ver ne ''
        or die "Unable to determine dist version\. Please use --version.\n";

    # final sanitazing of name and version
    $name =~ s/::/-/g;
    $ver = $self-&gt;sanitize_version($ver) unless $self-&gt;cfg-&gt;version;

    $name
        or $ver
        or die
        "Unable to determine distribution name and version. Aborting.\n";

    $name or die "Unable to determine distribution name. Aborting.\n";
    $ver  or die "Unable to determine distribution version. Aborting.\n";

    $self-&gt;perlname($name);
    $self-&gt;version($ver);

    $self-&gt;set_package_name;
}

sub extract_name_ver_from_build {
    my ( $self, $build ) = @_;
    my ( $file, $name, $ver, $vfrom, $dir );

    {
        local $/ = undef;
        my $fh = $self-&gt;_file_r($build);
        $file = $fh-&gt;getline;
    }

    # Replace q[quotes] by "quotes"
    $file =~ s/q\[(.+)]/'$1'/g;

    # Get the name
    if ($file =~ /([\'\"]?)
	    dist_name\1\s*
	    (=&gt;|,)
	    \s*
	    ([\'\"]?)
	    (\S+)\3/xs
        )
    {
        $name = $4;
    }
    elsif (
        $file =~ /([\'\"]?)
		 module_name\1\s*
		 (=&gt;|,)
		 \s*
		 (\S+)/xs
        )
    {
        $name = $self-&gt;unquote($2);
        $name =~ s/::/-/g;

        # just in case we need it later
        $vfrom = $name;
        $vfrom =~ s/-/::/g;
        $vfrom =~s{::}{/}g;
        $vfrom = "lib/$vfrom.pm";
    }
    $name =~ s/,.*$//;

    # band aid: need to find a solution also for build in directories
    # warn "name is $name (cpan name: $self-&gt;cfg-&gt;cpan)\n";
    $name = $self-&gt;cfg-&gt;cpan     if ( $name eq '__PACKAGE__' &amp;&amp; $self-&gt;cfg-&gt;cpan );
    $name = $self-&gt;cfg-&gt;cpanplus if ( $name eq '__PACKAGE__' &amp;&amp; $self-&gt;cfg-&gt;cpanplus );

    # Get the version
    if ( defined $self-&gt;cfg-&gt;version ) {

        # Explicitly specified
        $ver = $self-&gt;cfg-&gt;version;

    }
    elsif ( $file =~ /([\'\"]?)\sdist_version\1\s*(=&gt;|,)\s*([\'\"]?)([^\s,]*)\3/s ) {
        $ver = $4;

        # Where is the version taken from?
        $vfrom = $4
            if $file
                =~ /([\'\"]?)dist_version_from\1\s*(=&gt;|,)\s*([\'\"]?)([^\s,]*)\3/s;

    }
    elsif ( $file =~ /([\'\"]?)dist_version_from\1\s*(=&gt;|,)\s*([\'\"]?)([^\s,]*)\3/s )
    {
        $vfrom = $4;

    }

    $dir = dirname($build) || './';

    for ( ( $name, $ver ) ) {
        next unless defined;
        next unless /^\$/;

        # decode simple vars
        s/(\$\w+).*/$1/;
        if ( $file =~ /\Q$_\E\s*=\s*([\'\"]?)(\S+)\1\s*;/ ) {
            $_ = $2;
        }
    }

    unless ( defined $ver ) {
        local $/ = "\n";

        # apply the method used by makemaker
        if (    defined $dir
            and defined $vfrom
            and -f "$dir/$vfrom"
            and -r "$dir/$vfrom" )
        {
            my $fh = $self-&gt;_file_r("$dir/$vfrom");
            while ( my $lin = $fh-&gt;getline ) {
                if ( $lin =~ /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/ ) {
                    no strict;

                    #warn "ver: $lin";
                    $ver = ( eval $lin )[0];
                    last;
                }
            }
            $fh-&gt;close;
        }
        else {
            if ( $self-&gt;mod_cpan_version ) {
                $ver = $self-&gt;mod_cpan_version;
                warn "Cannot use internal module data to gather the "
                    . "version; using cpan_version\n";
            }
            else {
                die "Cannot use internal module data to gather the "
                    . "version; use --cpan or --version\n";
            }
        }
    }

    $self-&gt;perlname($name);
    $self-&gt;version($ver);

    $self-&gt;set_package_name;

    if ( defined($vfrom) ) {
        $self-&gt;extract_desc("$dir/$vfrom");
        $self-&gt;extract_basic_copyright("$dir/$vfrom");
    }
}

sub extract_name_ver_from_makefile {
    my ( $self, $makefile ) = @_;
    my ( $file, $name, $ver, $vfrom, $dir );

    {
        local $/ = undef;
        my $fh = $self-&gt;_file_r($makefile);
        $file = $fh-&gt;getline;
    }

    # Get the name
    if ($file =~ /([\'\"]?)
	    DISTNAME\1\s*
	    (=&gt;|,)
	    \s*
	    (\S+)/xs
        )
    {

        # Regular MakeMaker
        $name = $self-&gt;unquote($3);
    }
    elsif (
        $file =~ /([\'\"]?)
		 NAME\1\s*
		 (=&gt;|,)
		 \s*
		 (\S+)\s*,?/xs
        )
    {

        # Regular MakeMaker
        $name = $self-&gt;unquote($3);
    }
    elsif (
        $file =~ m{
                        name
                         \s*
                                 (\S+)          # Quoted name
                         \s*;
                 }xs
        )
    {

        # Module::Install syntax
        $name = $self-&gt;unquote($1);
    }
    $name =~ s/,.*$//;

    # band aid: need to find a solution also for build in directories
    # warn "name is $name (cpan name: $self-&gt;cfg-&gt;cpan)\n";
    $name = $self-&gt;cfg-&gt;cpan     if ( $name eq '__PACKAGE__' &amp;&amp; $self-&gt;cfg-&gt;cpan );
    $name = $self-&gt;cfg-&gt;cpanplus if ( $name eq '__PACKAGE__' &amp;&amp; $self-&gt;cfg-&gt;cpanplus );

    # Get the version
    if ( defined $self-&gt;cfg-&gt;version ) {

        # Explicitly specified
        $ver = $self-&gt;cfg-&gt;version;

    }
    elsif ( $file =~ /([\'\"]?)\bVERSION\1\s*(=&gt;|,)\s*([\'\"]?)([^\s,]*)\3/s ) {

        # Regular MakeMaker
        $ver = $4;

        # Where is the version taken from?
        $vfrom = $4
            if $file
                =~ /([\'\"]?)VERSION_FROM\1\s*(=&gt;|,)\s*([\'\"]?)([^\s,]*)\3/s;

    }
    elsif ( $file =~ /([\'\"]?)VERSION_FROM\1\s*(=&gt;|,)\s*([\'\"]?)([^\s,]*)\3/s )
    {

        # Regular MakeMaker pointing to where the version is taken from
        $vfrom = $4;

    }
    elsif (
        $file =~ m{
            \bversion\b\s*                  # The word version
            \(?\s*                          # Optional open-parens
            (['"]?)                         # Optional quotes
            ([\d_.]+)                       # The actual version.
            \1                              # Optional close-quotes
            \s*\)?                          # Optional close-parenthesis.
        }sx
    ) {

        # Module::Install
        $ver = $2;
    }

    $dir = dirname($makefile) || './';

    for ( ( $name, $ver ) ) {
        next unless defined;
        next unless /^\$/;

        # decode simple vars
        s/(\$\w+).*/$1/;
        if ( $file =~ /\Q$_\E\s*=\s*([\'\"]?)(\S+)\1\s*;/ ) {
            $_ = $2;
        }
    }

    unless ( defined $ver ) {
        local $/ = "\n";

        # apply the method used by makemaker
        if (    defined $dir
            and defined $vfrom
            and -f "$dir/$vfrom"
            and -r "$dir/$vfrom" )
        {
            my $fh = $self-&gt;_file_r("$dir/$vfrom");
            while ( my $lin = $fh-&gt;getline ) {
                if ( $lin =~ /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/ ) {
                    no strict;

                    #warn "ver: $lin";
                    $ver = ( eval $lin )[0];
                    last;
                }
            }
            $fh-&gt;close;
        }
        else {
            if ( $self-&gt;mod_cpan_version ) {
                $ver = $self-&gt;mod_cpan_version;
                warn "Cannot use internal module data to gather the "
                    . "version; using cpan_version\n";
            }
            else {
                die "Cannot use internal module data to gather the "
                    . "version; use --cpan or --version\n";
            }
        }
    }

    $self-&gt;perlname($name);
    $self-&gt;version($ver);

    $self-&gt;set_package_name;

    if ( defined($vfrom) ) {
        $self-&gt;extract_desc("$dir/$vfrom");
        $self-&gt;extract_basic_copyright("$dir/$vfrom");
    }
}

sub extract_desc {
    my ( $self, $file ) = @_;

    my $bin = $self-&gt;control-&gt;binary_tie-&gt;Values(0);
    my $desc = $bin-&gt;short_description;

    $desc and return;

    return unless -f $file;
    my ( $parser, $modulename );
    $parser = new DhMakePerl::PodParser;
    $parser-&gt;set_names(qw(NAME DESCRIPTION DETAILS));
    $parser-&gt;parse_from_file($file);
    if ( $desc ) {

        # No-op - We already have it, probably from the command line

    }
    elsif ( $self-&gt;meta-&gt;{abstract} ) {

        # Get it from META.yml
        $desc = $self-&gt;meta-&gt;{abstract};

    }
    elsif ( my $my_desc = $parser-&gt;get('NAME') ) {

        # Parse it, fix it, send it!
        $my_desc =~ s/^\s*\S+\s+-\s+//s;
        $my_desc =~ s/^\s+//s;
        $my_desc =~ s/\s+$//s;
        $my_desc =~ s/^([^\s])/ $1/mg;
        $my_desc =~ s/\n.*$//s;
        $desc = $my_desc;
    }

    if ( defined($desc) ) {
        # Replace linefeed (not followed by a space) in short description with
        # spaces
        $desc =~ s/\n(?=\S)/ /gs;
        $desc =~ s/^\s+//;      # strip leading spaces
    }

    # have a fall-back for the short description
    $desc ||= '(no short description found)';

    $bin-&gt;short_description($desc);

    my $long_desc;
    unless ( $bin-&gt;long_description ) {
        $long_desc 
            = $parser-&gt;get('DESCRIPTION')
            || $parser-&gt;get('DETAILS')
            || '';
        ( $modulename = $self-&gt;perlname ) =~ s/-/::/g;
        $long_desc =~ s/This module/$modulename/;
        $long_desc =~ s/This library/$modulename/;

        local ($Text::Wrap::columns) = 78;
        $long_desc = fill( "", "", $long_desc );
    }

    if ( defined($long_desc) ) {
        $long_desc =~ s/^[\s\n]+//s;
        $long_desc =~ s/\s+$//s;
        $long_desc =~ s/^\t/ /mg;
        $long_desc =~ s/\r//g;
        $long_desc = '(no description was found)' if $long_desc eq '';

        $bin-&gt;long_description(
            "$long_desc\n\nThis description was automagically extracted from the module by dh-make-perl.\n"
        );
    }

    $parser-&gt;cleanup;
}

sub check_for_xs {
    my ($self) = @_;

    # we need the relative path here. Otherwise the check will give bogus
    # results if the working dir matches the pattern
    my $rel_path = substr( $File::Find::name, length( $self-&gt;main_dir ) );
    ( $rel_path !~ m{/(?:examples?|samples|eg|t|docs|win32?|demos?)/} )
            and
    ( !$self-&gt;cfg-&gt;exclude or $rel_path !~ $self-&gt;cfg-&gt;exclude )
        &amp;&amp; /\.(xs|c|cpp|cxx)$/i
        &amp;&amp; do {
        $self-&gt;control-&gt;binary_tie-&gt;Values(0)-&gt;Architecture('any');
        };
}

sub extract_basic_copyright {
    my ( $self, $file ) = @_;

    for my $f ( map( $self-&gt;main_file($_), qw(LICENSE LICENCE COPYING) ) ) {
        if ( -f $f ) {
            my $fh = $self-&gt;_file_r($f);
            $self-&gt;copyright( join( '', $fh-&gt;getlines ) );
        }
    }

    if ( defined($file) ) {
        my ( $parser, $modulename );
        $parser = new DhMakePerl::PodParser;
        return unless -f $file;
        $parser-&gt;set_names(qw(COPYRIGHT AUTHOR AUTHORS));
        $parser-&gt;parse_from_file($file);

        $self-&gt;copyright( $parser-&gt;get('COPYRIGHT')
                || $parser-&gt;get('LICENSE')
                || $parser-&gt;get('COPYRIGHT &amp; LICENSE') )
            unless $self-&gt;copyright;

        if ( !$self-&gt;author ) {
            if ( ref $self-&gt;meta-&gt;{author} ) {

                # Does the author information appear in META.yml?
                $self-&gt;author( join( ', ', @{ $self-&gt;meta-&gt;{author} } ) );
            }
            else {

                # Get it from the POD - and clean up
                # trailing/preceding spaces!
                my $a = $parser-&gt;get('AUTHOR') || $parser-&gt;get('AUTHORS');
                $a =~ s/^\s*(\S.*\S)\s*$/$1/gs if $a;
                $self-&gt;author($a);
            }
        }

        $parser-&gt;cleanup;
    }
}

sub extract_docs {
    my ( $self ) = @_;

    my $dir = $self-&gt;main_dir;

    $dir .= '/' unless $dir =~ m(/$);
    find(
        {   preprocess =&gt; sub {
                my $bn = basename $File::Find::dir;
                return ()
                    if $bn eq '.svn-base'
                        or $bn eq '.svn'
                        or $bn eq '.git';

                return @_;
            },
            wanted =&gt; sub {
                push(
                    @{ $self-&gt;docs },
                    substr( $File::Find::name, length($dir) )
                    )
                    if (
                        $File::Find::name ne $self-&gt;main_dir . '/README'
                    and /^\b(README|TODO|BUGS|NEWS|ANNOUNCE)\b/i
                    and !/\.(pod|pm)$/
                    and ( !$self-&gt;cfg-&gt;exclude
                        or $File::Find::name !~ $self-&gt;cfg-&gt;exclude )
                    and !/\.svn-base$/
                    and $File::Find::name
                    !~ m{debian/README\.(?:source|[Dd]ebian)}
                    );
            },
        },
        $dir
    );
}

sub extract_examples {
    my ( $self ) = @_;

    my $dir = $self-&gt;main_dir;

    $dir .= '/' unless $dir =~ m{/$};
    find(
        sub {
            return if $_ eq '.';  # skip the directory itself
            my $exampleguess = substr( $File::Find::name, length($dir) );
            push( @{ $self-&gt;examples },
                ( -d $exampleguess ? $exampleguess . '/*' : $exampleguess ) )
                if ( /^(examples?|eg|samples?)$/i
                and ( !$self-&gt;cfg-&gt;exclude or $File::Find::name !~ $self-&gt;cfg-&gt;exclude )
                );
        },
        $dir
    );
}

sub read_rules {
    my $self = shift;

    return if $self-&gt;rules;

    my $file = $self-&gt;debian_file('rules');

    $self-&gt;rules( Debian::Rules-&gt;new($file) );
}

sub create_rules {
    my ( $self ) = @_;

    my $file = $self-&gt;debian_file('rules');

    $self-&gt;rules( Debian::Rules-&gt;new($file) );

    if ( $self-&gt;rules-&gt;is_dh7tiny ) {
        print "$file already uses DH7 tiny rules\n"
            if $self-&gt;cfg-&gt;verbose;
        return;
    }

    $self-&gt;backup_file($file);

    my $rulesname = 'rules.dh7.tiny';

    for my $source (
        catfile( $self-&gt;cfg-&gt;home_dir, $rulesname ),
        catfile( $self-&gt;cfg-&gt;data_dir, $rulesname )
    ) {
        if ( -e $source ) {
            print "Using rules: $source\n" if $self-&gt;cfg-&gt;verbose;
            $self-&gt;rules-&gt;read($source);
            last;
        };
    }
    $self-&gt;rules-&gt;write;
    chmod( 0755, $file ) or die "chmod($file): $!";
}

sub create_compat {
    my ( $self, $file ) = @_;

    my $fh = $self-&gt;_file_w($file);
    $fh-&gt;print( $self-&gt;cfg-&gt;dh, "\n" );
    $fh-&gt;close;
}

sub update_file_list( $ % ) {
    my ( $self, %p ) = @_;

    my $pkgname = $self-&gt;pkgname;

    while ( my ( $file, $new_content ) = each %p ) {
        next unless @$new_content;
        # pkgname.foo file
        my $pkg_file = $self-&gt;debian_file("$pkgname.$file");
        my %uniq_content;
        my @existing_content;

        # if a package.foo exists read its values first
        if ( -r $pkg_file ) {
            my $fh                = $self-&gt;_file_r($pkg_file);
            @existing_content = $fh-&gt;getlines;
            chomp(@existing_content);

            # make list of files for package.foo unique
            $uniq_content{$_} = 1 for @existing_content;
        }

        $uniq_content{$_} = 1 for @$new_content;

        # write package.foo file with unique entries
        open F, '&gt;', $pkg_file or die $!;
        for ( @existing_content, @$new_content ) {

            # we have the unique hash
            # we delete from it each printed line
            # so if a line is not in the hash, this means we have already
            # printed it
            next unless exists $uniq_content{$_};

            delete $uniq_content{$_};
            print F "$_\n";
        }
        close F;
    }
}

sub create_copyright {
    my ( $self, $filename ) = @_;

    my ( $fh, %fields, @res, @incomplete, $year );
    $fh = $self-&gt;_file_w($filename);

    # In case author string spawns more than one line, indent them all.
    my $cprt_author = $self-&gt;author || '(information incomplete)';
    $cprt_author =~ s/\n/\n    /gs;
    $cprt_author =~ s/^\s*$/    ./gm;

    push @res, 'Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/';

    # Header section
    %fields = (
        'Upstream-Name'    =&gt; $self-&gt;perlname,
        'Upstream-Contact' =&gt; $cprt_author,
        'Source'           =&gt; $self-&gt;upsurl
    );
    for my $key ( sort keys %fields ) {
        my $full = "$key";
        if ( $fields{$key} ) {
            push @res, "$full: $fields{$key}";
        }
        else {
            push @incomplete, "Could not get the information for $full";
        }
    }
    push( @res,
        "DISCLAIMER: This copyright info was automatically extracted ",
        " from the perl module. It may not be accurate, so you better ",
        " check the module sources in order to ensure the module for its ",
        " inclusion in Debian or for general legal information. Please, ",
        " if licensing information is incorrectly generated, file a bug ",
        " on dh-make-perl.",
        " NOTE: Don't forget to remove this disclaimer once you are happy",
        " with this file." );
    push @res, '';

    # Files section - We cannot "parse" the module's licensing
    # information for anything besides general information.
    push @res, 'Files: *';

    # Absence of author should have already been reported in the
    # Header section
    push @res, "Copyright: $cprt_author";

    # This is far from foolproof, but usually works with most
    # boilerplate-generated modules.
    #
    # We go over the most common combinations only

    my ( %texts, %licenses );
    %texts = (
        'Artistic' =&gt;
            " This program is free software; you can redistribute it and/or modify\n"
            . " it under the terms of the Artistic License, which comes with Perl.\n"
            . " .\n"
            . " On Debian systems, the complete text of the Artistic License can be\n"
            . " found in `/usr/share/common-licenses/Artistic'.",
        'Artistic-2.0' =&gt; do {
            require Software::License::Artistic_2_0;
            my $artistic2 = Software::License::Artistic_2_0-&gt;new(
                { holder =&gt; 'noname', } );
            my $text = $artistic2-&gt;license;
            $text =~ s/\n$//s;
            $text =~ s/^\n/.\n/mg;
            $text =~ s/^/ /mg;
            $text;
            },
        'GPL-1+' =&gt;
            " This program is free software; you can redistribute it and/or modify\n"
            . " it under the terms of the GNU General Public License as published by\n"
            . " the Free Software Foundation; either version 1, or (at your option)\n"
            . " any later version.\n"
            . " .\n"
            . " On Debian systems, the complete text of version 1 of the GNU General\n"
            . " Public License can be found in `/usr/share/common-licenses/GPL-1'.",
        'GPL-2' =&gt;
            " This program is free software; you can redistribute it and/or modify\n"
            . " it under the terms of the GNU General Public License as published by\n"
            . " the Free Software Foundation; version 2 dated June, 1991.\n"
            . " .\n"
            . " On Debian systems, the complete text of version 2 of the GNU General\n"
            . " Public License can be found in `/usr/share/common-licenses/GPL-2'.",
        'GPL-2+' =&gt;
            " This program is free software; you can redistribute it and/or modify\n"
            . " it under the terms of the GNU General Public License as published by\n"
            . " the Free Software Foundation; version 2 dated June, 1991, or (at your\n"
            . " option) any later version.\n"
            . " .\n"
            . " On Debian systems, the complete text of version 2 of the GNU General\n"
            . " Public License can be found in `/usr/share/common-licenses/GPL-2'.",
        'GPL-3' =&gt;
            " This program is free software; you can redistribute it and/or modify\n"
            . " it under the terms of the GNU General Public License as published by\n"
            . " the Free Software Foundation; version 3 dated June, 2007.\n"
            . " .\n"
            . " On Debian systems, the complete text of version 3 of the GNU General\n"
            . " Public License can be found in `/usr/share/common-licenses/GPL-3'.",
        'GPL-3+' =&gt;
            " This program is free software; you can redistribute it and/or modify\n"
            . " it under the terms of the GNU General Public License as published by\n"
            . " the Free Software Foundation; version 3 dated June, 2007, or (at your\n"
            . " option) any later version.\n"
            . " .\n"
            . " On Debian systems, the complete text of version 3 of the GNU General\n"
            . " Public License can be found in `/usr/share/common-licenses/GPL-3'.",
        'Apache-2.0' =&gt;
            " Licensed under the Apache License, Version 2.0 (the \"License\");\n"
            . " you may not use this file except in compliance with the License.\n"
            . " You may obtain a copy of the License at\n"
            . "     http://www.apache.org/licenses/LICENSE-2.0\n"
            . " Unless required by applicable law or agreed to in writing, software\n"
            . " distributed under the License is distributed on an \"AS IS\" BASIS,\n"
            . " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
            . " See the License for the specific language governing permissions and\n"
            . " limitations under the License.\n"
            . " .\n"
            . " On Debian systems, the complete text of the Apache License,\n"
            . " Version 2.0 can be found in `/usr/share/common-licenses/Apache-2.0'.",
        'unparsable' =&gt;
            " No known license could be automatically determined for this module.\n"
            . " If this module conforms to a commonly used license, please report this\n"
            . " as a bug in dh-make-perl. In any case, please find the proper license\n"
            . " and fix this file!"
    );

    if ( $self-&gt;meta-&gt;{license} or $self-&gt;copyright ) {
        my $mangle_cprt;

        # Pre-mangle the copyright information for the common similar cases
        $mangle_cprt = $self-&gt;copyright || '';    # avoid warning
        $mangle_cprt =~ s/GENERAL PUBLIC LICENSE/GPL/g;

        # Of course, more licenses (i.e. LGPL, BSD-like, Public
        # Domain, etc.) could be added... Feel free to do so. Keep in
        # mind that many licenses are not meant to be used as
        # templates (i.e. you must add the author name and some
        # information within the licensing text as such).
        if ( $self-&gt;meta-&gt;{license} ) {
            foreach ( @{ $self-&gt;meta-&gt;{license} } ) {
                if (/apache_2_0/) { $licenses{'Apache-2.0'}   = 1; next; }
                if (/artistic_1/) { $licenses{'Artistic'}     = 1; next; }
                if (/artistic_2/) { $licenses{'Artistic-2.0'} = 1; next; }

                # EU::MM and M::B converts the 'gpl' without a version to gpl_1.
                # As GPL without a version means *any* GPL, I think it's safe to use GPL-1+ here
                if (/gpl_1/) { $licenses{'GPL-1+'} = 1; next; }

                if (/perl_5/) {
                    $licenses{'GPL-1+'}   = 1;
                    $licenses{'Artistic'} = 1;
                    next;
                }
            }
        }
        else {
            if ( $mangle_cprt =~ /terms\s*as\s*Perl\s*itself/is ) {
              $licenses{'GPL-1+'}   = 1;
              $licenses{'Artistic'} = 1;
            }

            if ( $mangle_cprt =~ /[^L]GPL/ ) {
                if ( $mangle_cprt =~ /GPL.*version\s*1.*later\s+version/is ) {
                    $licenses{'GPL-1+'} = 1;
                }
                elsif (
                    $mangle_cprt =~ /GPL.*version\s*2.*later\s+version/is )
                {
                    $licenses{'GPL-2+'} = 1;
                }
                elsif ( $mangle_cprt =~ /GPL.*version\s*2/is ) {
                    $licenses{'GPL-2'} = 1;
                }
                elsif (
                    $mangle_cprt =~ /GPL.*version\s*3.*later\s+version/is )
                {
                    $licenses{'GPL-3+'} = 1;
                }
                elsif ( $mangle_cprt =~ /GPL.*version\s*3/is ) {
                    $licenses{'GPL-3'} = 1;
                }
            }

            if ( $mangle_cprt =~ /Artistic\s*License\s*2\.0/is ) {
                $licenses{'Artistic-2.0'} = 1;
            }
            elsif ( $mangle_cprt =~ /Artistic\s*License/is ) {
                $licenses{'Artistic'} = 1;
            }

            if ( $mangle_cprt =~ /Apache\s*License.*2\.0/is ) {
                $licenses{'Apache-2.0'} = 1;
            }

            # Other licenses?

            if ( !keys(%licenses) ) {
                $licenses{unparsable} = 1;
                push( @incomplete,
                    "Licensing information is present, but cannot be parsed"
                );
            }
        }

        push @res, "License: " . join( ' or ', sort keys %licenses );

    }
    else {
        push @res,        "License: ";
        push @incomplete, 'No licensing information found';
    }

    # debian/* files information - We default to the module being
    # licensed as the super-set of the module and Perl itself.
    $licenses{'Artistic'} = $licenses{'GPL-1+'} = 1;
    $year = (localtime)[5] + 1900;
    push( @res, "", "Files: debian/*" );
    if ( $self-&gt;cfg-&gt;command eq 'refresh' ) {
        my @from_changelog
            = $self-&gt;copyright_from_changelog( $self-&gt;get_developer, $year );
        $from_changelog[0] = "Copyright:" . $from_changelog[0];
        push @res, @from_changelog;
    }
    else {
        push @res, "Copyright: $year, " . $self-&gt;get_developer;
    }
    push @res, "License: " . join( ' or ', sort keys %licenses );

    map { $texts{$_} &amp;&amp; push( @res, '', "License: $_", $texts{$_} ) }
        sort keys %licenses;

    $fh-&gt;print( join( "\n", @res, '' ) );
    $fh-&gt;close;

    $self-&gt;_warn_incomplete_copyright( join( "\n", @incomplete ) )
        if @incomplete;
}

sub upsurl {
    my $self = shift;
    return sprintf( "https://metacpan.org/release/%s", $self-&gt;perlname );
}


my $ACTUAL_NAME_RE = '\pL[\s\pL\-\'\.]*\pL';

# See http://www.faqs.org/rfcs/rfc2822.html
# Section 3.4.1
use Email::Address;
my $EMAIL_RE = $Email::Address::addr_spec;

my $EMAIL_CHANGES_RE = qr{
    ^                           # beginining of line
    \s+\*\s                     # item marker
    Email\schange:\s            # email change token
    ($ACTUAL_NAME_RE)           # actual name
    \s+-&gt;\s+                    # gap between name and email
    ($EMAIL_RE)                 # email address
    $                           # end of line
}xms;

my $PERSON_PARSE_RE = qr{
    \A                          # beginining of string
    ($ACTUAL_NAME_RE)           # actual name
    \s                          # gap
    \&lt;$EMAIL_RE\&gt;               # logged email
    \z                          # end of string
}xms;

# This is what needs fixing.
sub copyright_from_changelog {
    my ( $self, $firstmaint, $firstyear ) = @_;
    my %maintainers = ();
    @{ $maintainers{$firstmaint} } = ($firstyear);
    my $chglog = Parse::DebianChangelog-&gt;init(
        { infile =&gt; $self-&gt;debian_file('changelog') } );
    my %email_changes = ();
    foreach ( $chglog-&gt;data() ) {
        my $person      = $_-&gt;Maintainer;
        my $date        = $_-&gt;Date;
        my @date_pieces = split( " ", $date );
        my $year        = $date_pieces[3];
        if (my %changes = ($_-&gt;Changes =~ m/$EMAIL_CHANGES_RE/xmsg)) {
            # This way round since we are going backward in time thru changelog
            foreach my $p (keys %changes) {
                $changes{$p} =~ s{[\s\n]+$}{}xms;
            }
            %email_changes = (
                %changes,
                %email_changes
            );
        }
        if (my ($name) = ($person =~ $PERSON_PARSE_RE)) {
            if (exists $email_changes{$name}) {
                $person = "$name &lt;$email_changes{$name}&gt;";
            }
        }
        if ( defined( $maintainers{$person} ) ) {
            push @{ $maintainers{$person} }, $year;
            @{ $maintainers{$person} } = sort( @{ $maintainers{$person} } );
        }
        else {
            @{ $maintainers{$person} } = ($year);
        }
    }
    my @strings;
    foreach my $maint_name ( keys %maintainers ) {
        my $str = " ";
        my %uniq = map { $_ =&gt; 0 } @{ $maintainers{$maint_name} };
        foreach ( sort keys %uniq ) {
            $str .= $_;
            $str .= ", ";
        }
        $str .= $maint_name;
        push @strings, $str;
    }
    @strings = sort @strings;
    return @strings;
}

sub _warn_incomplete_copyright {
    my $self = shift;

    print '*' x 10, '
Copyright information incomplete!

Upstream copyright information could not be automatically determined.

If you are building this package for your personal use, you might disregard
this information; however, if you intend to upload this package to Debian
(or in general, if you plan on distributing it), you must look into the
complete copyright information.

The causes for this warning are:
', @_, "\n";
}

sub write_source_format {
    my ( $self, $path ) = @_;

    my ( $vol, $dir, $file ) = splitpath($path);
    $dir = catpath( $vol, $dir );

    if ( $self-&gt;cfg-&gt;source_format eq '1.0' ) {
        # this is the default, remove debian/source
        File::Path::rmtree($dir);
    }
    else {
        # make sure the directory exists
        File::Path::mkpath($dir) unless -d $dir;

        my $fh = $self-&gt;_file_w($path);
        $fh-&gt;print( $self-&gt;cfg-&gt;source_format, "\n" );
        $fh-&gt;close;
    }
}

sub module_build {
    my $self = shift;

    # dehbelper prefers Makefile.PL over Build.PL unless the former is a
    # Module::Build::Compat wrapper
    return 'Module-Build' if $self-&gt;makefile_pl_is_MBC;

    return 'MakeMaker' if -e $self-&gt;makefile_pl;

    return ( -f $self-&gt;main_file('Build.PL') ) ? "Module-Build" : "MakeMaker";
}

=item explained_dependency I&lt;$reason&gt;, I&lt;$dependencies&gt;, I&lt;@dependencies&gt;

Adds the list of dependencies to I&lt;$dependencies&gt; and shows I&lt;$reason&gt; if in
verbose mode.

Used to both bump a dependency and tell the user why.

I&lt;$dependencies&gt; is an instance of L&lt;Debian::Dependencies&gt; class, and
I&lt;@dependencies&gt; is a list of L&lt;Debian::Dependency&gt; instances or strings.

The message printed looks like C&lt;&lt; $reason needs @dependencies &gt;&gt;.

=cut

sub explained_dependency {
    my ( $self, $reason, $deps, @to_add ) = @_;

    $deps-&gt;add(@to_add);

    warn sprintf( "%s needs %s\n", $reason, join( ', ', @to_add ) );
}

=item configure_cpan

Configure CPAN module. It is safe to call this method more than once, it will
do nothing if CPAN is already configured.

=cut

sub configure_cpan {
    my $self = shift;

    return if $CPAN::Config_loaded;

    my $save_cwd = getcwd();

    CPAN::HandleConfig-&gt;load( be_silent =&gt; not $self-&gt;cfg-&gt;verbose )
        if $self-&gt;cfg-&gt;network;

    unshift( @{ $CPAN::Config-&gt;{'urllist'} }, $self-&gt;cfg-&gt;cpan_mirror )
        if $self-&gt;cfg-&gt;cpan_mirror;

    $CPAN::Config-&gt;{'tar_verbosity'}     = $self-&gt;cfg-&gt;verbose ? 'v' : '';
    $CPAN::Config-&gt;{'load_module_verbosity'}
        = $self-&gt;cfg-&gt;verbose ? 'verbose' : 'silent';

    $CPAN::Config-&gt;{build_requires_install_policy} = 'no';
    $CPAN::Config-&gt;{prerequisites_policy} = 'ignore';

    chdir $save_cwd;
}

=item discover_dependencies

Just a wrapper around $self-&gt;control-&gt;discover_dependencies which provides the
right parameters to it.

Returns a list of missing modules.

=cut

sub discover_dependencies {
    my $self = shift;

    if ( my $apt_contents = $self-&gt;get_apt_contents ) {

        my $wnpp_query;
        $wnpp_query
            = Debian::WNPP::Query-&gt;new(
            { cache_file =&gt; catfile( $self-&gt;cfg-&gt;home_dir, 'wnpp.cache' ) } )
            if $self-&gt;cfg-&gt;network;

        # control-&gt;discover_dependencies needs configured CPAN
        $self-&gt;configure_cpan;

        return $self-&gt;control-&gt;discover_dependencies(
            {   dir          =&gt; $self-&gt;main_dir,
                verbose      =&gt; $self-&gt;cfg-&gt;verbose,
                apt_contents =&gt; $self-&gt;apt_contents,
                require_deps =&gt; $self-&gt;cfg-&gt;requiredeps,
                wnpp_query   =&gt; $wnpp_query,
                intrusive    =&gt; $self-&gt;cfg-&gt;intrusive,
            }
        );
    }
    else {
        warn "No APT contents can be loaded.\n";
        warn "Please install 'apt-file' package (at least version 2.5.0) and\n";
        warn "run 'apt-file update' as root.\n";
        warn "Dependencies not updated.\n";

        return ();
    }
}

=item discover_utility_deps

Determines whether a certain version of L&lt;debhelper(1)&gt; or L&lt;quilt(1)&gt; is
needed by the build process.

The following special cases are detected:

=over

=item Module::AutoInstall

If L&lt;Module::AutoInstall&gt; is discovered in L&lt;inc/&gt;, debhelper dependency is
raised to 7.2.13.

=item Module::Build::Tiny

if L&lt;Module::Build::Tiny&gt; is present in the build-dependencies, debhelper
dependency is raised to 9.20130630.

=item dh --with=quilt

C&lt;dh --with=quilt&gt; needs debhelper 7.0.8 and quilt 0.46-7.

=item dh --with=bash-completion

C&lt;dh --with=bash-completion&gt; needs debhelper 7.0.8 and bash-completion 1:1.0-3.

=item dh --with=perl_dbi

C&lt;dh --with=perl_dbi&gt; needs debhelper 7.0.8 and libdbi-perl 1.612.

=item dh --buildsystem=buildsystem

C&lt;dh --buildsystem=buildsystem&gt; needs debhelper 7.3.7.

=item quilt.make

If F&lt;/usr/share/quilt/quilt.make&gt; is included in F&lt;debian/rules&gt;, a
build-dependency on C&lt;quilt&gt; is added.

=item debhelper override targets

Targets named C&lt;override_dh_...&gt; are supported by debhelper since 7.0.50

=item Makefile.PL created by Module::Build::Compat

Building such packages requires debhelper 7.0.17 (see
L&lt;http://bugs.debian.org/496157&gt;) =back

=item Module::Build

The proper build-dependency in this case is

    perl

The on perl without a version is set as Lenny has already 5.10 which
includes first Module::Build.

=back

=cut

sub discover_utility_deps {
    my ( $self, $control ) = @_;

    my $deps  = $control-&gt;source-&gt;Build_Depends;

    # remove any existing dependencies
    $deps-&gt;remove( 'quilt', 'debhelper' );

    # start with the minimum
    my $debhelper_version = $self-&gt;cfg-&gt;dh;
    $debhelper_version = '9.20120312' if $debhelper_version eq '9';
    $deps-&gt;add( Debian::Dependency-&gt;new( 'debhelper', $debhelper_version ) );

    if ( $control-&gt;binary_tie-&gt;Values(0)-&gt;Architecture eq 'all' ) {
        $control-&gt;source-&gt;Build_Depends_Indep-&gt;add('perl');
    }
    else {
        $deps-&gt;add('perl');
    }

    $self-&gt;explained_dependency( 'Module::AutoInstall', $deps,
        'debhelper (&gt;= 7.2.13)' )
        if -e catfile( $self-&gt;main_dir, qw( inc Module AutoInstall.pm ) );
    $self-&gt;explained_dependency( 'Module::Build::Tiny', $deps,
        'debhelper (&gt;= 9.20130630)' )
        if $deps-&gt;has('libmodule-build-tiny-perl');

    for ( @{ $self-&gt;rules-&gt;lines } ) {
        $self-&gt;explained_dependency( 'dh --with', $deps,
            'debhelper (&gt;= 7.0.8)' )
            if /dh\s+.*--with/;

        $self-&gt;explained_dependency(
            'dh --with=quilt',
            $deps, 'quilt (&gt;= 0.46-7)',
        ) if /dh\s+.*--with[= ]quilt/;

        $self-&gt;explained_dependency(
            'dh --with=bash-completion',
            $deps,
            'bash-completion (&gt;= 1:1.0-3)'
        ) if (/dh\s+.*--with[= ]bash[-_]completion/);

        $self-&gt;explained_dependency(
            'dh --with=perl_dbi',
            $deps,
            'libdbi-perl (&gt;= 1.612)'
        ) if (/dh\s+.*--with[= ]perl[-_]dbi/);

        $self-&gt;explained_dependency( 'override_dh_* target',
            $deps, 'debhelper (&gt;= 7.0.50)' )
            if /^override_dh_/;

        $self-&gt;explained_dependency( 'quilt.make', $deps, 'quilt' )
            if m{^include /usr/share/quilt/quilt.make};

        $self-&gt;explained_dependency( 'dh* --max-parallel',
            $deps, 'debhelper (&gt;= 7.4.4)' )
            if /dh.* --max-parallel/;

        # Modular --buildsystem support for debhelper needs 7.3.7.
        $self-&gt;explained_dependency( 'dh* --buildsystem',
            $deps, 'debhelper (&gt;= 7.3.7)' )
            if /dh.* --buildsystem/;
    }

    if (    -e $self-&gt;main_file('Makefile.PL')
        and -e $self-&gt;main_file('Build.PL') )
    {
        $self-&gt;explained_dependency(
            'Compatibility Makefile.PL',
            $deps,
            'debhelper (&gt;= 7.0.17)',
            'perl'
        ) if $self-&gt;makefile_pl_is_MBC;
    }

    # there are old packages that still build-depend on libmodule-build-perl
    # or perl (&gt;= 5.10) | libmodule-build-perl.
    # Since M::B is part of perl 5.10, the build-dependency needs correction
    # and we replace this Build-Depends with simply perl, as lenny has the
    # required version.
    # Remove perl from Build-Depends-Indep as then perl will be already in
    # Build-Depends.
    if ( $self-&gt;module_build eq 'Module-Build' ) {
        $deps-&gt;remove('perl (&gt;= 5.10) | libmodule-build-perl');
        $deps-&gt;remove('libmodule-build-perl');
        $control-&gt;source-&gt;Build_Depends_Indep-&gt;remove('perl');
        $self-&gt;explained_dependency( 'Module::Build', $deps,
            'perl' );
    }

    # some mandatory dependencies
    my $bin_deps = $control-&gt;binary_tie-&gt;Values(0)-&gt;Depends;
    $bin_deps += '${shlibs:Depends}'
        if $self-&gt;control-&gt;binary_tie-&gt;Values(0)-&gt;Architecture eq 'any';
    $bin_deps += '${misc:Depends}, ${perl:Depends}';
}

=item makefile_pl_is_MBC

Checks if F&lt;Makefile.PL&gt; is a compatibility wrapper around Build.PL provided by
Module::Build::Compat.

=cut

sub makefile_pl_is_MBC
{
    my $self = shift;

    my $mf = $self-&gt;makefile_pl;

    return undef unless -e $mf;

    my $fh = $self-&gt;_file_r($mf);

    while( defined( $_ = &lt;$fh&gt; ) ) {
        if ( /^[^#"]*Module::Build::Compat/ ) {
            return 1;
        }
    }

    return 0;
}

=item backup_file(file_name)

Creates a backup copy of the specified file by adding C&lt;.bak&gt; to its name. If
the backup already exists, it is overwritten.

Does nothing unless the C&lt;backups&gt; option is set.

=cut

sub backup_file {
    my( $self, $file ) = @_;

    if ( $self-&gt;cfg-&gt;backups ) {
        warn "W: overwriting $file.bak\n"
            if -e "$file.bak" and $self-&gt;cfg-&gt;verbose;
        rename( $file, "$file.bak" );
    }
}

=item unquote(I&lt;string&gt;)

Runs its argument through L&lt;Text::Balanced&gt;'s C&lt;extract_quotelike&gt; method and
returns the extracted content with quotes removed. Dies if C&lt;extract_quotelike&gt;
can't find quoted string.

=cut

sub unquote {
    my ( $self, $input ) = @_;

    my $unquoted = (extract_quotelike($input))[5];

    die "Unable to find quoted string in [$input]" unless defined $unquoted;

    return $unquoted;
}

=back

=cut

sub _file_r {
    my ( $self, $filename ) = @_;

    my $fh = IO::File-&gt;new( $filename, 'r' )
        or die "Cannot open $filename: $!\n";
    return $fh;
}

sub _file_w {
    my ( $self, $filename ) = @_;

    my $fh = IO::File-&gt;new( $filename, 'w' )
        or die "Cannot open $filename: $!\n";
    return $fh;
}

=head1 COPYRIGHT &amp; LICENSE

=over 4

=item Copyright (C) 2000, 2001 Paolo Molaro &lt;lupus@debian.org&gt;

=item Copyright (C) 2002, 2003, 2008 Ivan Kohler &lt;ivan-debian@420.am&gt;

=item Copyright (C) 2003, 2004 Marc 'HE' Brockschmidt &lt;he@debian.org&gt;

=item Copyright (C) 2005-2007 Gunnar Wolf &lt;gwolf@debian.org&gt;

=item Copyright (C) 2006 Frank Lichtenheld &lt;djpig@debian.org&gt;

=item Copyright (C) 2007-2013 Gregor Herrmann &lt;gregoa@debian.org&gt;

=item Copyright (C) 2007,2008,2009,2010,2012,2013 Damyan Ivanov &lt;dmn@debian.org&gt;

=item Copyright (C) 2008, Roberto C. Sanchez &lt;roberto@connexer.com&gt;

=item Copyright (C) 2009-2011, Salvatore Bonaccorso &lt;carnil@debian.org&gt;

=item Copyright (C) 2011, Nicholas Bamber &lt;nicholas@periapt.co.uk&gt;

=back

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.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301 USA.

=cut

1;
</pre></body></html>