4
4
package Text::PerlPP ;
5
5
6
6
# Semantic versioning, packed per Perl rules. Must always be at least one
7
- # digit left of the decimal, and six digits right of the decimal.
8
- our $VERSION = ' 0.500004' ;
7
+ # digit left of the decimal, and six digits right of the decimal. For
8
+ # prerelease versions, put an underscore before the last three digits.
9
+ our $VERSION = ' 0.600001' ;
9
10
10
11
use 5.010001;
11
12
use strict;
@@ -667,17 +668,24 @@ sub Include { # As ProcessFile(), but for use within :macro
667
668
$self -> StartOB(); # re-open a plain-text OB
668
669
} # Include
669
670
670
- sub OutputResult {
671
+ sub FinalizeResult {
671
672
my $self = shift ;
672
673
my $contents_ref = shift ; # reference
673
- my $fname = shift ; # "" or other false value => STDOUT
674
- my $proc ;
675
- my $out_fh ;
676
674
677
- for $proc ( @{$self -> {Postprocessors }} ) {
675
+ for my $proc ( @{$self -> {Postprocessors }} ) {
678
676
&$proc ( $contents_ref );
679
677
}
678
+ return $contents_ref ;
679
+ } # FinalizeResult()
680
680
681
+ sub OutputResult {
682
+ my $self = shift ;
683
+ my $contents_ref = shift ; # reference
684
+ my $fname = shift ; # "" or other false value => STDOUT
685
+
686
+ $self -> FinalizeResult( $contents_ref );
687
+
688
+ my $out_fh ;
681
689
if ( $fname ) {
682
690
open ( $out_fh , " >" , $fname ) or die $! ;
683
691
} else {
@@ -799,34 +807,34 @@ sub Main {
799
807
}
800
808
801
809
if ($self -> {Opts }-> {PRINT_VERSION }) { # print version, raw and dotted
802
- $Text::PerlPP::VERSION =~ m < ^([^\. ]+)\. (\d {3})(\d {3})> ;
803
- printf " PerlPP version %d .%d .%d ($VERSION )\n " , $1 , $2 , $3 ;
810
+ $Text::PerlPP::VERSION =~ m < ^([^\. ]+)\. (\d {3})(_?)(\d {3})> ;
811
+ printf " PerlPP version %d .%d .%d ($VERSION )%s \n " , $1 , $2 , $4 ,
812
+ ($3 ? ' (dev)' : ' ' );
804
813
if ($self -> {Opts }-> {PRINT_VERSION } > 1) {
805
814
print " Script: $0 \n Text::PerlPP: $INC {'Text/PerlPP.pm'}\n " ;
806
815
}
807
816
return EXIT_OK;
808
817
}
809
818
810
- # Preamble
811
-
812
819
# Save
813
820
push @Instances , $self ;
814
821
815
822
$self -> {Package } = $self -> {Opts }-> {INPUT_FILENAME };
816
823
$self -> {Package } =~ s / ^.*?([a-z_][a-z_0-9.]*).pl?$/ $1 / i ;
817
824
$self -> {Package } =~ s / [^a-z0-9_]/ _/ gi ;
818
- # $self->{Package} is not the whole name, so can start with a number.
825
+ # Not the whole name yet , so can start with a number.
819
826
$self -> {Package } = " PPP_$self ->{Package}$#Instances " ;
820
827
821
828
# Make $self accessible from inside the package.
822
829
# This has to happen first so that :macro or :immediate blocks in the
823
830
# script can access it while the input is being parsed.
824
831
{
825
832
no strict ' refs' ;
826
- ${ " $self ->{Package}::" . PPP_SELF_INSIDE }
827
- = $Text::PerlPP::Instances [$#Instances ];
833
+ ${ " $self ->{Package}::" . PPP_SELF_INSIDE } = $self ;
828
834
}
829
835
836
+ # --- Preamble -----------
837
+
830
838
$self -> StartOB(); # Output from here on will be included in the generated script
831
839
832
840
# Help the user know where to look
@@ -838,7 +846,7 @@ sub Main {
838
846
emit " use constant { true => !!1, false => !!0 };\n " ;
839
847
emit ' our $' . PPP_SELF_INSIDE . " ;\n " ; # Lexical alias for $self
840
848
841
- # Definitions
849
+ # --- Definitions --------
842
850
843
851
# Transfer parameters from the command line (-D) to the processed file,
844
852
# as textual representations of expressions.
@@ -902,6 +910,8 @@ sub Main {
902
910
}
903
911
emit " );\n " ;
904
912
913
+ # --- User input ---------
914
+
905
915
# Initial code from the command line, if any
906
916
if ($self -> {Opts }-> {EVAL }) {
907
917
$self -> emit_pound_line( ' <-e>' , 1 );
@@ -913,7 +923,7 @@ sub Main {
913
923
914
924
my $script = $self -> EndOB(); # The generated Perl script
915
925
916
- # --- Run it ---
926
+ # --- Run it -------------
917
927
if ( $self -> {Opts }-> {DEBUG } ) {
918
928
print $script ;
919
929
0 commit comments