Debian::Package::Make::TemplateDir - Perl extension for autobuilding Debian packages


Debian-Package-Make documentation Contained in the Debian-Package-Make distribution.

Index


Code Index:

NAME

Top

Debian::Package::Make::TemplateDir - Perl extension for autobuilding Debian packages

SYNOPSIS

Top

DESCRIPTION

Top

ATTRIBUTES

Top

template_dir

The directory from which prepare_files will fetch the templates. If template_dir is not set explicitly, it is derived from the program name and the name of the class.

PUBLIC INTERFACE

Top

new

template_dir

Calls Debian::Package::Make::new() and sets the template_dir attribute.

prepare_files

prepare_files populates $self-{files}> using files from a template directory (template_dir parameter).

Files within this directory that end with .in are treated as templates that are processed using process_template.

Note: In order for dpkg-buildpackage to function correctly, debian/control, debian/changelog, debian/rules must be provided by the template dir.

BUGS

Top

* This module lacks documentation. For the time being, please refer to the scripts in the examples directory.

SEE ALSO

Top

Debian::Package::Make

AUTHOR

Top

Hilko Bengen, <bengen@debian.org>

COPYRIGHT AND LICENSE

Top


Debian-Package-Make documentation Contained in the Debian-Package-Make distribution.
package Debian::Package::Make::TemplateDir;

use strict;
use warnings;

our $VERSION = 0.04;

use Debian::Package::Make 0.04;

our @ISA    = qw(Debian::Package::Make);
our @EXPORT = qw(@ATTRIBUTES);

push @ATTRIBUTES, qw( template_dir );

use File::Find;
use Cwd;

sub new {
    my ( $class, %param ) = @_;
    my $self = $class->SUPER::new(%param);
    $self->{template_dir} ||= $param{template_dir};
    if ( !$self->{template_dir} ) {
        my ($source) = ( lc($class) =~ /^(?:debian::package::make::)?(.*)$/i );
        $source =~ s/::/-/g;
        my ($path) = $0 =~ m(^(.*)/.+$); $path ||= '.';
        $self->{template_dir} ||= "$path/$source.template";
    }
    bless $self, $class;
}

sub prepare_files {
    my ( $self, %param ) = @_;
    my %f = %{ $self->{files} };
    my $td = $param{template_dir} || $self->template_dir;
    find(
        sub {
            if (   $File::Find::name !~ /(?:\.ex|~)$/i
                && $File::Find::name !~ /\/(?:\.svn|\.git|CVS)/
                && -f $_
                && !-f "$_.in" )
            {
                {
                    my ($fn) = $File::Find::name =~ m(^$td/*(.*)$);
                    my $fh;
                    open $fh, '<', $_ or warn "Can't read $fn.\n";
                    local $/;
                    $f{$fn} = <$fh>;
                    close $fh;
                }
            }
        },
        $td );
    $self->{files} = \%f;
    $self->process_templates;
}

1;