ARSperl
view release on metacpan or search on metacpan
ARS/CodeTemplate.pm view on Meta::CPAN
}
sub procdef {
my( $text ) = @_;
my $outfile;
if( defined $opt{'o'} ){
$outfile = $opt{'o'};
}else{
$outfile = '-';
}
open( OUTFILE, ">$outfile" ) or die "$outfile: $!\n";
print OUTFILE get_header( $outfile, $0 ) if $opt{'o'};
print OUTFILE $text;
close OUTFILE;
}
sub include {
my( $file ) = @_;
local $/ = undef;
local *FILE;
open( FILE, $file ) or do {
warn "Cannot open \"$file\": $!\n";
return undef;
};
my $data = <FILE>;
close FILE;
return $data;
}
sub modByRegex {
package main;
my( $val, @regex ) = @_;
foreach my $regex ( @regex ){
eval "\$val =~ $regex";
warn $@, "\n" if $@;
}
return $val;
}
sub get_header {
my( $of, $tpt ) = @_;
my $HEADER = << "+";
/*******************************************************************************
** **
** Automatically genenerated <OUTFILE> file.
** D O N O T E D I T ! ! ! ! **
** Edit <TEMPLATE> instead.
** **
*******************************************************************************/
+
my @HEADER = split( /\n/, $HEADER );
$HEADER = '';
$of =~ s|.*[\\/]||;
$tpt =~ s|.*[\\/]||;
foreach $line ( @HEADER ){
if( $line =~ s/<OUTFILE>/$of/ || $line =~ s/<TEMPLATE>/$tpt/ ){
$line .= ' ' x (78 - length($line)) . '*/';
}
$HEADER .= "$line\n";
}
return $HEADER;
}
1;
( run in 0.725 second using v1.01-cache-2.11-cpan-f56aa216473 )