ARSperl

 view release on metacpan or  search on metacpan

ARS/CodeTemplate.pm  view on Meta::CPAN

	my( $input ) = @_;

	my @input = split( /\n/, $input );
	my( $pFlag, $pCode, $output ) = ( 0, '', '' );
	my $line;

	foreach $line ( @input ){
		if( $line =~ /^@@\s+(\S+)\s+(.*)$/ ){
			my( $openMode, $outFile ) = ( $1, $2 );
			if( $outFile =~ /^<@(.*)@>\s*$/ ){
				eval( 'package '.caller()."; \$outFile = $1; package ARS::CodeTemplate;" );
#				print "OUTFILE: $outFile\n";
			}
#			print "OM($openMode) FILE($outFile)\n";
			die "Syntax error in \"$line\"\n" unless $openMode =~ /^[>|]+$/;
			if( defined $opt{debug} ){
				print "#------------------------------------------------------------\n";
				print "# OUTPUT:  $line\n";
				print $pCode;
				print "#------------------------------------------------------------\n\n";
			}else{
				eval( 'package '.caller()."; $pCode; package ARWT::Template;" );
				if( $@ ){
					warn $@, "\n";
					exit 1;
				}
				open( OUTPUT, "$openMode $outFile" ) or die "Open Error($openMode $outFile): $!\n";
				print OUTPUT $output;
				close OUTPUT;
			}
			( $pFlag, $pCode, $output ) = ( 0, '', '' );
		}elsif( $line =~ s/^@>+// ){

ARS/CodeTemplate.pm  view on Meta::CPAN

					}
				}
			}
		}
	}

	if( defined $opt{debug} ){
		print $pCode;
		exit;
	}else{
		eval( 'package '.caller()."; $pCode; package ARWT::Template;" );
		if( $@ ){
			warn $@, "\n";
			exit 1;
		}
	}
	return $output;
}


use Getopt::Long;



( run in 0.218 second using v1.01-cache-2.11-cpan-27979f6cc8f )