@@ -69,6 +69,9 @@ package PerlPP;
69
69
my $Defs_RE = false; # Regex that matches any -D name
70
70
my %Defs_repl_text = (); # Replacement text for -D names
71
71
72
+ # -s definitions.
73
+ my %Sets = (); # Command-line -s arguments
74
+
72
75
# Output-buffer stack
73
76
my @OutputBuffers = (); # each entry is a two-element array
74
77
@@ -565,6 +568,15 @@ sub Main {
565
568
}
566
569
567
570
# Now do SETS: -s or --set, into %S by analogy with -D and %D.
571
+
572
+ # Save a copy for use at generation time
573
+ %Sets = map { my $v = eval (${$opts {SETS }}{$_ });
574
+ warn " Could not evaluate -s \" $_ \" : $@ " if $@ ;
575
+ $_ => ($v // true)
576
+ }
577
+ keys %{$opts {SETS }};
578
+
579
+ # Make the copy for runtime
568
580
print " my %S = (\n " ;
569
581
for my $defname (keys %{$opts {SETS }}) {
570
582
my $val = ${$opts {SETS }}{$defname };
@@ -636,14 +648,18 @@ =head1 OPTIONS
636
648
637
649
Output to B<filename > instead of STDOUT.
638
650
639
- =item -D, --define B<name > =B<value >
651
+ =item -D, --define B<name > [ =B<value > ]
640
652
641
653
In the generated script, set C<< $D{B<name > } >> to B<value > .
642
654
The hash C<%D > always exists, but is empty if no B<-D > options are
643
655
given on the command line.
644
656
657
+ The B<name > will also be replaced with the B<value > in the text of the file.
658
+ If B<value > cannot be evaluated, no substitution is made for B<name > .
659
+
645
660
If you omit the B<< =value >> , the value will be the constant C<true >
646
- (see L</"The generated script"> , below).
661
+ (see L</"The generated script"> , below), and no text substitution
662
+ will be performed.
647
663
648
664
This also saves the value, or C<undef > , in the generation-time
649
665
hash C<< %Defs >>. This can be used, e.g., to select include filenames
@@ -661,6 +677,26 @@ =head1 OPTIONS
661
677
Don't evaluate Perl code, just write the generated code to STDOUT.
662
678
By analogy with the C<-E > option of gcc.
663
679
680
+ =item -s, --set B<name > [=B<value > ]
681
+
682
+ As B<-D > , but:
683
+
684
+ =over
685
+
686
+ =item *
687
+
688
+ Does not substitute text in the body of the document;
689
+
690
+ =item *
691
+
692
+ Saves into C<< %Sets >> at generation time; and
693
+
694
+ =item *
695
+
696
+ Saves into C<< %S >> in the generated script.
697
+
698
+ =back
699
+
664
700
=item --man
665
701
666
702
Full documentation, viewed in your default pager if configured.
@@ -677,7 +713,8 @@ =head1 OPTIONS
677
713
678
714
=head1 DEFINITIONS
679
715
680
- B<-D > items may be evaluated in any order --- do not rely on left-to-right
716
+ B<-D > and B<-s > items may be evaluated in any order ---
717
+ do not rely on left-to-right
681
718
evaluation in the order given on the command line.
682
719
683
720
If your shell strips quotes, you may need to escape them: B<value > must
@@ -722,8 +759,8 @@ =head1 COPYRIGHT
722
759
723
760
Code at L<https://github.com/d-ash/perlpp> .
724
761
Distributed under MIT license.
725
- By Andrey Shubin (L<[email protected] > ); additional contributions by
726
- Chris White (cxw42 at Github).
762
+ By Andrey Shubin (d-ash at Github; L<[email protected] > ) and
763
+ Chris White (cxw42 at Github; L<[email protected] > ).
727
764
728
765
=cut
729
766
0 commit comments