App-Oozie

 view release on metacpan or  search on metacpan

lib/App/Oozie/Deploy/Template.pm  view on Meta::CPAN

    my $self = shift;
    my($var_file, $tt_variable, $tt_varname) = @_;

    my $tmpl = <<'TMPL';
[% {% tt_variable %} %]
[% FOREACH entry IN {% tt_varname %}  %]
        <property>
            <name>[%  entry.key   %]</name>
            <value>[% entry.value %]</value>
        </property>
[% END %]
TMPL

    my $tt = Template->new(
        START_TAG => '{%',
        END_TAG   => '%}',
    );

    $tt->process(
        \$tmpl,
        {
            tt_variable => $tt_variable,
            tt_varname  => $tt_varname,
        },
        \my $buf,
    );

    open my $FH, '>', $var_file or die "Can't write to $var_file: $!";
    print $FH "$buf\n";
    if ( ! close $FH ) {
        $self->logger->warn(
            sprintf 'Failed to close %s: %s',,
                        $var_file,
                        $!,
        );
    }

    $self->logger->debug( sprintf 'meta file created as: %s', $var_file )
        if $self->verbose;

    return $var_file;
}

sub _pre_process_ttconfig_into_tempfile {
    my $self   = shift;
    my $opt    = shift || {};
    my $logger = $self->logger;

    my($fh_tmp_cfg, $tmp_cfg_file) = File::Temp::tempfile(
                                        EMPTY_STRING,
                                        DIR => resolve_tmp_dir(),
                                    );

    my $file = File::Spec->catfile( $self->ttlib_base_dir, 'ttree.cfg' );

    my $maybe_log_line = sub {
        my $config_line = shift || return;
        if ( $config_line =~ m{ \A copy }xms ) {
            $logger->info(
                sprintf 'Files matching this pattern will be copied as-is: /%s/',
                            trim +(split m{ [=] }xms, $config_line, 2)[LAST_ELEM]
            );
        }
        return;
    };

    open my $FH, '<', $file or die "Failed to read $file: $!";
    while ( <$FH> ) {
        $maybe_log_line->( $_ );
        print $fh_tmp_cfg $_;
    }
    if ( ! close $FH ) {
        $self->logger->warn(
            sprintf 'Failed to close %s: %s',,
                        $file,
                        $!,
        );
    }

    # Attach the correct lib dir to the conf
    printf $fh_tmp_cfg "\nlib = %s\n", $self->ttlib_base_dir;

    # custom includes
    if ( $opt->{temp_lib} && -d $opt->{temp_lib} && -r _ ) {
        printf $fh_tmp_cfg "\nlib = %s\n", $opt->{temp_lib};
    }

    $logger->debug( sprintf 'TT conf file created as %s', $tmp_cfg_file )
        if $self->verbose;

    return $tmp_cfg_file;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

App::Oozie::Deploy::Template

=head1 VERSION

version 0.020

=head1 SYNOPSIS

TBD

=head1 DESCRIPTION

TBD

=head1 NAME

App::Oozie::Deploy::Template - Template Toolkit compiler for Oozie workflow specs.



( run in 2.201 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )