1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
package ExtUtils::Builder::Node;
$ExtUtils::Builder::Node::VERSION = '0.017';
use strict;
use warnings;
use parent qw/ExtUtils::Builder::Action::Composite/;
use Carp 'croak';
sub new {
my ($class, %args) = @_;
croak('Attribute target is not defined') if not $args{target};
$args{actions} = [ map { $_->flatten } @{ $args{actions} // [] } ];
$args{dependencies} //= [];
$args{type} //= delete $args{phony} ? 'phony' : 'file';
return $class->SUPER::new(%args);
}
sub flatten {
my $self = shift;
return @{ $self->{actions} };
}
sub target {
my $self = shift;
return $self->{target};
}
sub dependencies {
my $self = shift;
return @{ $self->{dependencies} };
}
sub type {
my $self = shift;
return $self->{type};
}
sub phony {
my $self = shift;
return $self->{type} eq 'phony';
}
sub mergeable {
my $self = shift;
return $self->{type} eq 'phony' && !@{ $self->{actions} };
}
sub newer_than {
my ($self, $mtime) = @_;
return 1 if $self->{type} eq 'phony';
return -d $self->{target} || (-e _ && $mtime <= -M _);
}
1;
# ABSTRACT: An ExtUtils::Builder Node
__END__
=pod
=encoding UTF-8
=head1 NAME
ExtUtils::Builder::Node - An ExtUtils::Builder Node
=head1 VERSION
version 0.017
=head1 SYNOPSIS
ExtUtils::Builder::Node->new(
target => $target_name,
dependencies => \@dependencies,
actions => \@actions,
);
=head1 DESCRIPTION
A node is the equivalent of a makefile entry. In essence it boils down to its three attributes: C<target> (the name of the target), C<dependencies>(the names of the dependencies) and C<actions>. A Node is a L<composite action|ExtUtils::Builder::Action::Composite>, meaning that in can be executed or serialized as a whole.
=head1 ATTRIBUTES
=head2 target
The target filename of this node.
=head2 dependencies
The (file)names of the dependencies of this node.
=head2 actions
A list of L<actions|ExtUtils::Builder::Action> for this node.
=head2 type
This must be one of C<file> or C<phony>. In the latter case the target will not be represented on the filesystem.
=head2 phony
B<Deprecated>.
Instead, pass C<< type => 'phony' >>
=head1 METHODS
=head2 mergeable
This returns true if a node is mergeable, i.e. it's phony and has no actions.
=for Pod::Coverage flatten
execute
to_command
to_code
newer_than
=head1 AUTHOR
Leon Timmermans <fawaka@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|