Skip to content

Commit

Permalink
Merge pull request #29 from cxw42/prepost
Browse files Browse the repository at this point in the history
Minor updates; v0.600.1
  • Loading branch information
cxw42 authored Sep 10, 2018
2 parents d6ca649 + 53d91f0 commit fa7ffb0
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 25 deletions.
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ t/05-external-command.t
t/06-macro.t
t/07-invalid.t
t/08-persistent-state.t
t/09-preproc.t
t/10-postproc.t
t/a.txt
t/b.txt
t/c.txt
Expand Down
17 changes: 15 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ my $secure_perl_path = get_perl_filename();
sub MY::postamble { # TODO also handle Windows nmake syntax (SET vs. export)
return <<EOT;
authortest:
\tRELEASE_TESTING=1 prove -l xt"
\tRELEASE_TESTING=1 prove -l xt
testhere: # Run the tests from lib rather than blib
\t"$secure_perl_path" -Ilib -e 'use Test::Harness "runtests"; runtests \@ARGV;' -- t/*.t
Expand All @@ -44,9 +44,10 @@ WriteMakefile(
LICENSE => 'mit',

EXE_FILES => [ 'bin/perlpp' ],

MIN_PERL_VERSION => '5.010',
CONFIGURE_REQUIRES => {
'ExtUtils::MakeMaker' => '0',
'ExtUtils::MakeMaker' => '6.46',
},
BUILD_REQUIRES => {
'App::FatPacker' => '0',
Expand Down Expand Up @@ -74,6 +75,18 @@ WriteMakefile(
'Getopt::Long' => '2.5', # Per issue #17
'Pod::Usage' => '0',
},

META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
url => 'https://github.com/interpreters/perlpp.git',
web => 'https://github.com/interpreters/perlpp',
},
},
},

dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Text-PerlPP-* fatlib' },
);
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The build system is straight ExtUtils::MakeMaker.
Before developing, run

perl Makefile.PL
cpanm --installdeps . # if you have cpanminus installed
cpanm --installdeps . # if you have cpanminus installed

Then, to test your code directly from the lib/ directory, run

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,7 @@ FILETYPE can be determined with `:set ft?`

Distributed under the MIT license --- see
[LICENSE.txt](LICENSE.txt) for details.
By Andrey Shubin (d-ash at Github) and Chris White (cxw42 at Github).

By Andrey Shubin ([d-ash](https://github.com/d-ash)) and
Chris White (CXW; [cxw42](https://github.com/cxw42));
additional contributions by Mohammad S Anwar (MANWAR;
[manwar](https://github.com/manwar)).
20 changes: 17 additions & 3 deletions bin/perlpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,26 @@ L<ExtUtils::PerlPP>, L<HTML::EP>, L<PML>, L<Preproc::Tiny>, L<ePerl>, L<iperl>.
=head1 AUTHORS
Andrey Shubin (d-ash at Github; L<[email protected]>) and
Chris White (cxw42 at Github; L<[email protected]>).
=over
=item *
Originally by Andrey Shubin (d-ash at Github; C<[email protected]>)
=item *
Currently maintained by Chris White (CXW; cxw42 at Github;
C<[email protected]>).
=item *
Other contributions by Mohammad S. Anwar (MANWAR; manwar at Github)
=back
=head1 LICENSE AND COPYRIGHT
Copyright 2013-2018 Andrey Shubin and Christopher White.
Copyright 2013-2018 PerlPP Contributors (listed above)
This program is distributed under the MIT (X11) License:
L<http://www.opensource.org/licenses/mit-license.php>
Expand Down
42 changes: 26 additions & 16 deletions lib/Text/PerlPP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
package Text::PerlPP;

# Semantic versioning, packed per Perl rules. Must always be at least one
# digit left of the decimal, and six digits right of the decimal.
our $VERSION = '0.500004';
# digit left of the decimal, and six digits right of the decimal. For
# prerelease versions, put an underscore before the last three digits.
our $VERSION = '0.600001';

use 5.010001;
use strict;
Expand Down Expand Up @@ -667,17 +668,24 @@ sub Include { # As ProcessFile(), but for use within :macro
$self->StartOB(); # re-open a plain-text OB
} #Include

sub OutputResult {
sub FinalizeResult {
my $self = shift;
my $contents_ref = shift; # reference
my $fname = shift; # "" or other false value => STDOUT
my $proc;
my $out_fh;

for $proc ( @{$self->{Postprocessors}} ) {
for my $proc ( @{$self->{Postprocessors}} ) {
&$proc( $contents_ref );
}
return $contents_ref;
} #FinalizeResult()

sub OutputResult {
my $self = shift;
my $contents_ref = shift; # reference
my $fname = shift; # "" or other false value => STDOUT

$self->FinalizeResult( $contents_ref );

my $out_fh;
if ( $fname ) {
open( $out_fh, ">", $fname ) or die $!;
} else {
Expand Down Expand Up @@ -799,34 +807,34 @@ sub Main {
}

if($self->{Opts}->{PRINT_VERSION}) { # print version, raw and dotted
$Text::PerlPP::VERSION =~ m<^([^\.]+)\.(\d{3})(\d{3})>;
printf "PerlPP version %d.%d.%d ($VERSION)\n", $1, $2, $3;
$Text::PerlPP::VERSION =~ m<^([^\.]+)\.(\d{3})(_?)(\d{3})>;
printf "PerlPP version %d.%d.%d ($VERSION)%s\n", $1, $2, $4,
($3 ? ' (dev)' : '');
if($self->{Opts}->{PRINT_VERSION} > 1) {
print "Script: $0\nText::PerlPP: $INC{'Text/PerlPP.pm'}\n";
}
return EXIT_OK;
}

# Preamble

# Save
push @Instances, $self;

$self->{Package} = $self->{Opts}->{INPUT_FILENAME};
$self->{Package} =~ s/^.*?([a-z_][a-z_0-9.]*).pl?$/$1/i;
$self->{Package} =~ s/[^a-z0-9_]/_/gi;
# $self->{Package} is not the whole name, so can start with a number.
# Not the whole name yet, so can start with a number.
$self->{Package} = "PPP_$self->{Package}$#Instances";

# Make $self accessible from inside the package.
# This has to happen first so that :macro or :immediate blocks in the
# script can access it while the input is being parsed.
{
no strict 'refs';
${ "$self->{Package}::" . PPP_SELF_INSIDE }
= $Text::PerlPP::Instances[$#Instances];
${ "$self->{Package}::" . PPP_SELF_INSIDE } = $self;
}

# --- Preamble -----------

$self->StartOB(); # Output from here on will be included in the generated script

# Help the user know where to look
Expand All @@ -838,7 +846,7 @@ sub Main {
emit "use constant { true => !!1, false => !!0 };\n";
emit 'our $' . PPP_SELF_INSIDE . ";\n"; # Lexical alias for $self

# Definitions
# --- Definitions --------

# Transfer parameters from the command line (-D) to the processed file,
# as textual representations of expressions.
Expand Down Expand Up @@ -902,6 +910,8 @@ sub Main {
}
emit ");\n";

# --- User input ---------

# Initial code from the command line, if any
if($self->{Opts}->{EVAL}) {
$self->emit_pound_line( '<-e>', 1 );
Expand All @@ -913,7 +923,7 @@ sub Main {

my $script = $self->EndOB(); # The generated Perl script

# --- Run it ---
# --- Run it -------------
if ( $self->{Opts}->{DEBUG} ) {
print $script;

Expand Down
2 changes: 1 addition & 1 deletion t/05-external-command.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ my @testcases=(
['', '<?! false ?> More stuff', qr{^$} , qr{command 'false' failed: process exited}],
['-k', '<?! false ?> More stuff', qr{^ More stuff$} , qr{command 'false' failed: process exited}],
# Using capturing for part of the command
['', '<?!echo -n "?>Hello!?<?"?>', qr{^Hello!\?$}],
['', '<?!echo "?>Hello!?<?"?>', qr{^Hello!\?\n$}],

); #@testcases

Expand Down
3 changes: 3 additions & 0 deletions t/09-preproc.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!perl
use Test::More;
plan skip_all => 'Not yet implemented';
3 changes: 3 additions & 0 deletions t/10-postproc.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!perl
use Test::More;
plan skip_all => 'Not yet implemented';

0 comments on commit fa7ffb0

Please sign in to comment.