App-hopen

 view release on metacpan or  search on metacpan

lib/App/hopen/Gen.pm  view on Meta::CPAN


C<$dag> is the command graph, and C<$data> is the output from the
command graph.

C<finalize> is always called with named parameters.

=cut

sub finalize { }

=head2 _run_build

(Optional)
Implementation of L</run_build>.  The default does not die, but does warn().

=cut

sub _run_build {
    warn "This generator is not configured to run a build tool.  Sorry!";
} #_run_build()

=head2 visit_goal

Add a target corresponding to the name of the goal.  Usage:

    $Generator->visit_goal($node, $node_inputs);

This happens while the command graph is being run.

This can be overriden by a generator that wants to handle
L<Data::Hopen::G::Goal> nodes differently.
For example, the generator may want to change the goal's C<outputs>.

=cut

sub visit_goal {
    my ($self, %args) = getparameters('self', [qw(goal node_inputs)], @_);

    # --- Add the goal to the asset graph ---

    #my $asset_goal = $self->_assets->goal($args{goal}->name);
    my $phony_asset = App::hopen::Asset->new(
        target => $args{goal}->name,
        made_by => $self,
    );
    my $phony_node = $self->asset(-asset => $phony_asset, -how => '');
        # \p how defined but falsy => it's a goal
    $self->connect($phony_node, $self->asset_default_goal);

    # Pull the inputs.  TODO refactor out the code in common with
    # AhG::Cmd::input_assets().
    my $hrSourceFiles =
        $args{node_inputs}->find(-name => 'made',
                                    -set => '*', -levels => 'local') // {};
    die 'No input files to goal ' . $args{goal}->name
        unless scalar keys %$hrSourceFiles;

    my $lrSourceFiles = $hrSourceFiles->{(keys %$hrSourceFiles)[0]};
    hlog { 'found inputs to goal', $args{goal}->name, Dumper($lrSourceFiles) } 2;

    # TODO? verify that all the assets are actually in the graph first?
    $self->connect($_, $phony_node) foreach @$lrSourceFiles;

} #visit_goal()

=head2 visit_node

(Optional)
Do whatever the generator wants to do with a L<Data::Hopen::G::Node> that
is not a Goal (see L</visit_goal>).  By default, no-op.  Usage:

    $generator->visit_node($node)

=cut

sub visit_node { }

1;
__END__
# vi: set fdm=marker: #



( run in 0.995 second using v1.01-cache-2.11-cpan-e1769b4cff6 )