| 1 | |||
| 2 | ################################################################################### | ||
| 3 | # | ||
| 4 | # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de | ||
| 5 | # Embperl - Copyright (c) 2008-2015 Gerald Richter | ||
| 6 | # Embperl - Copyright (c) 2015-2023 actevy.io | ||
| 7 | # | ||
| 8 | # You may distribute under the terms of either the GNU General Public | ||
| 9 | # License or the Artistic License, as specified in the Perl README file. | ||
| 10 | # | ||
| 11 | # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR | ||
| 12 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | ||
| 13 | # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
| 14 | # | ||
| 15 | |||
| 16 | ################################################################################### | ||
| 17 | |||
| 18 | |||
| 19 | package Embperl::Inline ; | ||
| 20 | |||
| 21 | use strict ; | ||
| 22 | use vars qw{$options} ; | ||
| 23 | |||
| 24 | no warnings "uninitialized" ; | ||
| 25 | |||
| 26 | sub import | ||
| 27 | { | ||
| 28 | if (ref $_[1] eq 'HASH') | ||
| 29 | { | ||
| 30 | $options = $_[1] ; | ||
| 31 | } | ||
| 32 | else | ||
| 33 | { | ||
| 34 | $options = undef ; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | sub compile | ||
| 39 | |||
| 40 | { | ||
| 41 | my ($code, $line, $file, $package) = @_ ; | ||
| 42 | |||
| 43 | my $debug = 0 ; #0x7fffffff ; | ||
| 44 | if ($Embperl::req) | ||
| 45 | { | ||
| 46 | #$debug = $Embperl::req -> config -> debug ; | ||
| 47 | } | ||
| 48 | |||
| 49 | #print STDERR "compile: $file, code = $code, options = $options\n" ; | ||
| 50 | |||
| 51 | Embperl::Execute ({ 'inputfile' => $file, | ||
| 52 | 'input' => $code, | ||
| 53 | 'mtime' => -M $file, | ||
| 54 | 'import' => 0, | ||
| 55 | 'firstline' => $line, | ||
| 56 | 'package' => $package, | ||
| 57 | #'debug' => $debug, | ||
| 58 | ($options?(%$options):()), | ||
| 59 | 'use_env' => 1}) ; | ||
| 60 | } | ||
| 61 | |||
| 62 | |||
| 63 | use Filter::Simple ; | ||
| 64 | use Embperl ; | ||
| 65 | |||
| 66 | FILTER | ||
| 67 | { | ||
| 68 | s/\n__EMBPERL__(.+)$/\nBEGIN { my \$line = __LINE__ - 1 ; my \$code = q{$1}; Embperl::Inline::compile (\\\$code, \$line, __FILE__, __PACKAGE__)}/s ; | ||
| 69 | } ; | ||
| 70 | |||
| 71 | |||
| 72 | 1 ; | ||
| 73 | |||
| 74 | =pod | ||
| 75 | |||
| 76 | =head1 NAME | ||
| 77 | |||
| 78 | Embperl::Inline - Inline Embperl code in Perl modules | ||
| 79 | |||
| 80 | =head1 SYNOPSIS | ||
| 81 | |||
| 82 | package MyTest ; | ||
| 83 | |||
| 84 | use Embperl::Inline ; | ||
| 85 | |||
| 86 | __EMBPERL__ | ||
| 87 | |||
| 88 | [$ sub foo $] | ||
| 89 | |||
| 90 | [- | ||
| 91 | $a = 99 ; | ||
| 92 | -] | ||
| 93 | |||
| 94 | <p>a=[+ $a +]</p> | ||
| 95 | [$endsub$] | ||
| 96 | |||
| 97 | |||
| 98 | =head1 DESCRIPTION | ||
| 99 | |||
| 100 | Embperl::Inline allows you to inline Embperl code in Perl modules. | ||
| 101 | The benfit is that you are able to install it like a normal | ||
| 102 | Perl module and it's available site wide, without the need | ||
| 103 | for any program to know where it resides. | ||
| 104 | |||
| 105 | Also it allows you to add markup sections to Perl objects and | ||
| 106 | calling (and overriding it) like normal Perl methods. | ||
| 107 | |||
| 108 | The only thing that needs to be done for using it, is to | ||
| 109 | use Embperl::Inline and to place your Embperl code after | ||
| 110 | the C<__EMBPERL__> keyword. | ||
| 111 | |||
| 112 | After the use Embperl::Inline it is possible to specify Embperl parameters e.g.: | ||
| 113 | |||
| 114 | use Embperl::Inline { options => &Embperl::Constant::optKeepSpaces }; | ||
| 115 | |||
| 116 | =head1 Author | ||
| 117 | |||
| 118 | G. Richter (richter at embperl dot org) | ||
| 119 | |||
| 120 | =head1 See Also | ||
| 121 | |||
| 122 | perl(1), Embperl |