Document::Maker - Makefile-like functionality in Perl


Document-Maker documentation Contained in the Document-Maker distribution.

Index


Code Index:

NAME

Top

Document::Maker - Makefile-like functionality in Perl

VERSION

Top

Version 0.022

SYNOPSIS

Top

    my $maker = Document::Maker->new;

    $maker->parser->parse_target( "tgt/a.out" => "src/defs.txt", 
        do => sub {
            my $target = shift;
            my $file = shift; # tgt/a.out
            ....
        },
    );

    $maker->make("tgt/a.out"); # Will only make if "tgt/a.out" is older than "src/defs.txt" or doesn't exist

DESCRIPTION

Top

Document::Maker is intended to have similar functionality as GNU make with additional enhancements.

WARNING: Although this is a 3rd-iteration attempt at Makefile-ness, the API is very fluid and could change in future versions.

WARNING: There may be bugs lurking about, I'll be happy to entertain bug reports.

Already working

Target-from-one-source

    $maker->parser->parse_target( "tgt/a.out" => "src/defs.txt", 
        do => sub {
            my $target = shift;
            my $file = shift; # tgt/a.out
            ....
        },
    );

Target-from-many-sources

    $maker->parser->parse_target( "tgt/a.out" => [ "src/defs.txt", "src/xyzzy.txt" ], 
        do => sub {
            my $target = shift;
            my $file = shift; # tgt/a.out
            ....
        },
    );

Many-targets-dependent-on-many-sources

    $maker->parser->parse_target( [ "tgt/a.out", "tgt/b.out" ] => [ "src/defs.txt", "src/xyzzy.txt" ], 
        do => sub {
            my $target = shift;
            my $file = shift;
            ....
        },
    );

Non-file, Target-only

    $maker->parser->parse_simple_target( "configure",
        do => sub {
            my $target = shift; # No second argument
            ....
        },
    );

Target/source-patterns

    $maker->parser->parse_pattern_target(qw( tgt/%.html src/%.in a b c d e ), [ "header.html" ], { 
        do => sub {
            my $target = shift;
            my $file = shift; # tgt/a.html, tgt/b.html, etc.
            my $source_file = shift; # src/a.in, src/b.in, etc.
            ....
        },
    });

Target/source-patterns based on crawling through a directory

    # This will crawl src/ looking for every file matching the src pattern and making a target out of it
    $maker->parser->parse_pattern_target(qw( tgt/%.html src/%.in src/* ), [ "header.html" ], { 
        do => sub {
            my $target = shift;
            my $file = shift;
            my $source_file = shift;
            ....
        },
    });

Waiting to be implemented

.PHONY targets (always_make flag, sort-of implemented via simple targets)

Control of intermediate targets/sources

Better control of make conditions (should_make parameter)

Shell-like "do" arguments, similar to a real Makefile

For example, something like:

        $maker->parser->parse...(..., do => \<<_END_);
    @echo "Using m4 first before getting a line count"
    m4 < main.m4 $< | wc -l > $@
    _END_

Consistent handling of make failures/stale files

Last-chance wildcard targets

Document and test advanced patterns (embedded regexp, etc.)

AUTHOR

Top

Robert Krimen, <rkrimen at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-document-maker at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Document-Maker. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Document::Maker

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Document-Maker

* CPAN Ratings

http://cpanratings.perl.org/d/Document-Maker

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Document-Maker

* Search CPAN

http://search.cpan.org/dist/Document-Maker

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Document-Maker documentation Contained in the Document-Maker distribution.
package Document::Maker;

use warnings;
use strict;

our $VERSION = '0.022';

use Moose;

use Moose::Util::TypeConstraints;
use Path::Class;

type 'Path::Class::File' => where { $_->isa("Path::Class::File") };
coerce 'Path::Class::File' => from 'Str' => via { Path::Class::File->new($_) };

with map { "Document::Maker::Role::$_" } qw/Logging/;

has target_maker_registry => qw/is ro/, default => sub { [] };
has parser => qw/is ro lazy 1/, default => sub {
    require Document::Maker::Parser;
    return Document::Maker::Parser->new(maker => shift)
};

sub can_make {
    my $self = shift;
    my $name = shift;

    return 1 if $self->find_target($name);
    return 0;
}

sub should_make {
    my $self = shift;
    my $name = shift;

    return 0 unless my $target = $self->find_target($name);
    return $target->should_make;
}

sub make {
    my $self = shift;
    for my $name (@_) {
        $self->log->debug("Try to make: $name");
        $self->log->debug("Couldn't find target to make: $name") and next unless my $target = $self->find_target($name);
        $self->log->debug("Shouldn't make: $name") and next unless $target->should_make;
        $target->make;
    }
}

sub find_target {
    my $self = shift;
    my $name = shift;

    return unless my $target_maker_registry = $self->target_maker_registry;
    my $target;
    for (@$target_maker_registry) {
        last if $target = $_->can_make($name);
    }
    return $target;
}

sub register_target_maker {
    my $self = shift;
    my $target_maker = shift;
    push @{ $self->target_maker_registry }, $target_maker;
}

1; # End of Document::Maker