Author: richter
Date: Wed Nov  2 14:00:14 2005
New Revision: 330373

URL: http://svn.apache.org/viewcvs?rev=330373&view=rev
Log:
    - Added Module Embperl::Inline, which allows to embed
      Embperl code in an ordinary Perl module. This makes
      is easy to install system wide libraries, which need
      to contain Embperl code/markup. See perldoc Embperl::Inline
    - [$ sub $] now can takes arguments and inital code like:
        [$ sub foo ($self, $a, $b)  my $c = $self -> {bar} $] 
    - Embperl subroutines are now called in array context, to
      allow to return multiple return values.
    - Added validate type TimeValue, which is a numeric value
      followed by s, m, h, d or w.
    - Added validate type PosInteger, which is a positiv integer
      value
    - Fixed Segfault that could occur when a Embperl sub does
      not contain anything.


Added:
    perl/embperl/trunk/Embperl/Form/Validate/PosInteger.pm   (with props)
    perl/embperl/trunk/Embperl/Form/Validate/TimeValue.pm   (with props)
    perl/embperl/trunk/Embperl/Inline.pm   (with props)
    perl/embperl/trunk/test/cmp/subargs.htm   (with props)
    perl/embperl/trunk/test/html/subargs.htm   (with props)
Modified:
    perl/embperl/trunk/Changes.pod
    perl/embperl/trunk/Embperl.pm
    perl/embperl/trunk/Embperl.pod
    perl/embperl/trunk/Embperl/Syntax/EmbperlBlocks.pm
    perl/embperl/trunk/MANIFEST
    perl/embperl/trunk/epcomp.c
    perl/embperl/trunk/test.pl
    perl/embperl/trunk/test/conf/httpd.conf.src

Modified: perl/embperl/trunk/Changes.pod
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/Changes.pod?rev=330373&r1=330372&r2=330373&view=diff
==============================================================================
--- perl/embperl/trunk/Changes.pod (original)
+++ perl/embperl/trunk/Changes.pod Wed Nov  2 14:00:14 2005
@@ -2,8 +2,22 @@
 
 =head1 2.0.2_dev (Not yet released, only in the L<"SVN"|SVN.pod>)
 
+    - Added Module Embperl::Inline, which allows to embed
+      Embperl code in an ordinary Perl module. This makes
+      is easy to install system wide libraries, which need
+      to contain Embperl code/markup. See perldoc Embperl::Inline
+    - [$ sub $] now can takes arguments and inital code like:
+        [$ sub foo ($self, $a, $b)  my $c = $self -> {bar} $] 
+    - Embperl subroutines are now called in array context, to
+      allow to return multiple return values.
+    - Added validate type TimeValue, which is a numeric value
+      followed by s, m, h, d or w.
+    - Added validate type PosInteger, which is a positiv integer
+      value
     - Added Support for calling Embperl::Object::Execute inside
       an Embperl page. (Allow to nest new requests)      
+    - Fixed Segfault that could occur when a Embperl sub does
+      not contain anything.
     - Fixed compile problem with timezone on BSD systems
     - Fixed URLs in website to work correctly on static mirrors
     - Embperl development has been moved from CVS to SVN. 

Modified: perl/embperl/trunk/Embperl.pm
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl.pm?rev=330373&r1=330372&r2=330373&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl.pm (original)
+++ perl/embperl/trunk/Embperl.pm Wed Nov  2 14:00:14 2005
@@ -49,7 +49,7 @@
 
 @ISA = qw(Exporter DynaLoader);
 
-$VERSION = '2.0.1' ;
+$VERSION = '2.0.2_dev' ;
 
 
 if ($modperl  = $ENV{MOD_PERL})

Modified: perl/embperl/trunk/Embperl.pod
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl.pod?rev=330373&r1=330372&r2=330373&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl.pod (original)
+++ perl/embperl/trunk/Embperl.pod Wed Nov  2 14:00:14 2005
@@ -365,8 +365,7 @@
 
 The difference is that the Execute function will reset the internal
 states of Embperl like they were before the subrountine call, when 
-the subroutine returns. Also Execute could handle recursive call, which
-currently not work when calling it as a Perl subroutine.
+the subroutine returns. 
 
 You may also pass Parameters to the subroutine:
 
@@ -378,6 +377,24 @@
   
   [- foo ('value') -]
 
+
+In Embperl 2.0.2 and up you can use a shortcut syntax for passing parameters:
+
+    [$ sub foo ($p) $]
+     <p> Here we show the first parameter [+ $p +]</p>
+    [$ endsub $]
+
+This behaves the same as the example above, but in addition the parameters
+defined in this way are lexcialy scoped and therefore only available inside
+the subroutine.
+
+In addtion you can define some initial Perl code for the subroutine:
+
+   [$ sub foo ($a, $b)
+   my $c = $a + $b ;
+   $]
+     <p> The result is [+ $c +]</p>
+   [$ endsub $]
 
 If you have a couple of commonly used subroutines you can define then in one
 file and import them into the modules where they are neccesary:

Added: perl/embperl/trunk/Embperl/Form/Validate/PosInteger.pm
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl/Form/Validate/PosInteger.pm?rev=330373&view=auto
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Validate/PosInteger.pm (added)
+++ perl/embperl/trunk/Embperl/Form/Validate/PosInteger.pm Wed Nov  2 14:00:14 
2005
@@ -0,0 +1,43 @@
+
+###################################################################################
+#
+#   Embperl - Copyright (c) 1997-2004 Gerald Richter / ecos gmbh   www.ecos.de
+#
+#   You may distribute under the terms of either the GNU General Public
+#   License or the Artistic License, as specified in the Perl README file.
+#
+#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
+#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+#
+#   $Id: Integer.pm,v 1.3 2004/01/23 06:50:57 richter Exp $
+#
+###################################################################################
+
+
+package Embperl::Form::Validate::PosInteger ;
+
+use base qw(Embperl::Form::Validate::Integer);
+
+
+# --------------------------------------------------------------
+
+sub validate 
+    {
+    my ($self, $key, $value, $fdat, $pref) = @_ ;
+    
+    return $value =~ /^\s*[0-9+][0-9]*\s*$/ ? undef : ['validate_number', 
$value] ;
+    }
+
+# --------------------------------------------------------------
+
+sub getscript_validate 
+    {
+    my ($self, $arg, $pref) = @_ ;
+    
+    return ('obj.value.search(/^\s*[0-9+][0-9]*\s*$/) >= 0', 
['validate_number', "'+obj.value+'"]) ;
+    }
+
+
+
+1;

Propchange: perl/embperl/trunk/Embperl/Form/Validate/PosInteger.pm
------------------------------------------------------------------------------
    svn:executable = *

Added: perl/embperl/trunk/Embperl/Form/Validate/TimeValue.pm
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl/Form/Validate/TimeValue.pm?rev=330373&view=auto
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Validate/TimeValue.pm (added)
+++ perl/embperl/trunk/Embperl/Form/Validate/TimeValue.pm Wed Nov  2 14:00:14 
2005
@@ -0,0 +1,68 @@
+
+###################################################################################
+#
+#   Embperl - Copyright (c) 1997-2004 Gerald Richter / ecos gmbh   www.ecos.de
+#
+#   You may distribute under the terms of either the GNU General Public
+#   License or the Artistic License, as specified in the Perl README file.
+#
+#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
+#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+#
+#   $Id: Integer.pm,v 1.3 2004/01/23 06:50:57 richter Exp $
+#
+###################################################################################
+
+
+package Embperl::Form::Validate::TimeValue ;
+
+use base qw(Embperl::Form::Validate::Integer);
+
+my %error_messages = 
+(
+    de => 
+    {
+       validate_timevalue => 'Feld %0: "%1" ist keine gültige Zeit. Geben Sie 
eine Zahl gefolgt von s, m, h, d oder w ein.',
+    },
+
+    en =>
+    {
+       validate_timevalue => 'Field %0: "%1" isn\\\'t a valid time value. 
Please enter a number followed by s, m, h, d or w.',
+    }
+ );
+
+# --------------------------------------------------------------
+
+sub getmsg
+    {
+    my ($self, $id, $language, $default_language) = @_ ;
+
+    return $error_messages{$language}{$id} || 
+           $error_messages{$default_language}{$id} ||
+           $self -> SUPER::getmsg ($id, $language, $default_language) ;
+    }
+
+
+
+# --------------------------------------------------------------
+
+sub validate 
+    {
+    my ($self, $key, $value, $fdat, $pref) = @_ ;
+    
+    return $value =~ /^\s*[0-9+][0-9]*(?:s|m|h|d|w)\s*$/ ? undef : 
['validate_timevalue', $value] ;
+    }
+
+# --------------------------------------------------------------
+
+sub getscript_validate 
+    {
+    my ($self, $arg, $pref) = @_ ;
+    
+    return ('obj.value.search(/^\s*[0-9+][0-9]*(?:s|m|h|d|w)\s*$/) >= 0', 
['validate_timevalue', "'+obj.value+'"]) ;
+    }
+
+
+
+1;

Propchange: perl/embperl/trunk/Embperl/Form/Validate/TimeValue.pm
------------------------------------------------------------------------------
    svn:executable = *

Added: perl/embperl/trunk/Embperl/Inline.pm
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl/Inline.pm?rev=330373&view=auto
==============================================================================
--- perl/embperl/trunk/Embperl/Inline.pm (added)
+++ perl/embperl/trunk/Embperl/Inline.pm Wed Nov  2 14:00:14 2005
@@ -0,0 +1,90 @@
+

+###################################################################################

+#

+#   Embperl - Copyright (c) 1997-2005 Gerald Richter / ecos gmbh   www.ecos.de

+#

+#   You may distribute under the terms of either the GNU General Public

+#   License or the Artistic License, as specified in the Perl README file.

+#

+#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR

+#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED

+#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

+#

+#   $Id$

+#

+###################################################################################

+

+

+package Embperl::Inline ;

+

+sub compile

+

+    {

+    my ($code, $line, $file, $package) = @_ ;

+        

+    Embperl::Execute ({ 'inputfile' => $file, 

+                       'input'     => $code,

+                       'mtime'     => -M $file,

+                       'import'    => 0,

+                       'firstline' => $line,

+                       'package'   => $package,

+                        'use_env'   => 1}) ;

+    }

+

+

+use Filter::Simple ;

+use Embperl ;

+

+FILTER 

+    { 

+    s/\n__EMBPERL__(.+)$/\nBEGIN { my \$line = __LINE__ - 2 ; my \$code = 
q{$1}; Embperl::Inline::compile (\\\$code, \$line, __FILE__, __PACKAGE__)}/s ;

+    } ; 

+

+

+1 ;

+

+=pod

+

+=head1 NAME

+

+Embperl::Inline - Inline Embperl code in Perl modules

+

+=head1 SYNOPSIS

+

+    package MyTest ;

+    

+    use Embperl::Inline ;

+    

+    __EMBPERL__

+    

+    [$ sub foo $]

+    

+    [-

+    $a = 99 ;

+    -]

+    

+    <p>a=[+ $a +]</p>

+    [$endsub$]

+

+

+=head1 DESCRIPTION

+

+Embperl::Inline allow to inline Embperl code in Perl modules.

+The benfit is that you are able to install it like a normal

+Perl module and it's available site wide, without the need

+for any programm to know where it resides.

+

+Also it allows to add markup sections to Perl objects and

+calling (and overriding it) like normal Perl methods.

+

+The only thing that needs to be done for using it, is to

+use Embperl::Inline and to place your Embperl code after

+the C<__EMBPERL__> keyword.

+

+=head1 Author

+

+G. Richter ([EMAIL PROTECTED])

+

+=head1 See Also

+

+perl(1), Embperl


Propchange: perl/embperl/trunk/Embperl/Inline.pm
------------------------------------------------------------------------------
    svn:executable = *

Modified: perl/embperl/trunk/Embperl/Syntax/EmbperlBlocks.pm
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl/Syntax/EmbperlBlocks.pm?rev=330373&r1=330372&r2=330373&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Syntax/EmbperlBlocks.pm (original)
+++ perl/embperl/trunk/Embperl/Syntax/EmbperlBlocks.pm Wed Nov  2 14:00:14 2005
@@ -371,8 +371,27 @@
                 ) ;
     $self -> AddMetaStartEnd ('sub', 'endsub',
                 { 
-                perlcode => 'sub _ep_sub_%&<noname>% { ', 
-                perlcodeend => '};  sub %^subname% { my @_ep_save ; 
Embperl::Cmd::SubStart($_ep_DomTree,%$q%,[EMAIL PROTECTED]); my $_ep_ret = 
_ep_sub_%^subname% (@_); Embperl::Cmd::SubEnd($_ep_DomTree,[EMAIL PROTECTED]); 
return $_ep_ret } ; $_ep_exports{%^"subname%} = \&%^subname% ; ', 
+                perlcode => 'sub _ep_sub_ ', 
+                compiletimeperlcode => q[ 
+                                          my $args = %&'<noname>% ;
+                                            if ($args =~ /^([^ 
]+)\s*\((.*?)\)\s*(.*?)$/s)
+                                                {
+                                                $Embperl::req -> component -> 
code ("sub _ep_sub_$1 { my ($2) = [EMAIL PROTECTED] ; $3 ") ;
+                                                }
+                                            else
+                                                {
+                                                $args =~ /^([^ ]+)\s*(.*?)$/s ;
+                                                $Embperl::req -> component -> 
code ("sub _ep_sub_$1 { $2 ") ;
+                                                }
+                                         ], 
+                perlcodeend => ' };  sub #subname# { my @_ep_save ; 
Embperl::Cmd::SubStart($_ep_DomTree,%$q%,[EMAIL PROTECTED]); my @_ep_ret = 
_ep_sub_#subname# (@_); Embperl::Cmd::SubEnd($_ep_DomTree,[EMAIL PROTECTED]); 
return @_ep_ret } ; $_ep_exports{%^"subname%} = \&#subname# ; ', 
+                compiletimeperlcodeend => q[ 
+                                          my $args = %^'subname% ;
+                                          $args =~ s/\s+.+$//s ;
+                                          my $code = $Embperl::req -> 
component -> code ;
+                                          $code =~ s/#subname#/$args/g ;
+                                          $Embperl::req -> component -> code 
($code);
+                                         ], 
                 removenode => 10,
                 mayjump     => 1,
                 stackname2   => 'subname',

Modified: perl/embperl/trunk/MANIFEST
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/MANIFEST?rev=330373&r1=330372&r2=330373&view=diff
==============================================================================
--- perl/embperl/trunk/MANIFEST (original)
+++ perl/embperl/trunk/MANIFEST Wed Nov  2 14:00:14 2005
@@ -18,9 +18,12 @@
 Embperl/Form/Validate/IPAddr.pm
 Embperl/Form/Validate/IPAddr_Mask.pm
 Embperl/Form/Validate/Integer.pm
+Embperl/Form/Validate/PosInteger.pm
 Embperl/Form/Validate/Select.pm
 Embperl/Form/Validate/TimeHHMM.pm
 Embperl/Form/Validate/TimeHHMMSS.pm
+Embperl/Form/Validate/TimeValue.pm
+Embperl/Inline.pm
 Embperl/Log.pm
 Embperl/Mail.pm
 Embperl/Module.pm
@@ -352,6 +355,7 @@
 test/cmp/ssiep.htm
 test/cmp/stdout.htm
 test/cmp/sub.htm
+test/cmp/subargs.htm
 test/cmp/subempty.htm
 test/cmp/subout.htm
 test/cmp/subreq.htm
@@ -558,6 +562,7 @@
 test/html/spaces.htm
 test/html/stdout/stdout.htm
 test/html/sub.htm
+test/html/subargs.htm
 test/html/subempty.htm
 test/html/subexec.htm
 test/html/subimp.htm

Modified: perl/embperl/trunk/epcomp.c
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/epcomp.c?rev=330373&r1=330372&r2=330373&view=diff
==============================================================================
--- perl/embperl/trunk/epcomp.c (original)
+++ perl/embperl/trunk/epcomp.c Wed Nov  2 14:00:14 2005
@@ -2088,7 +2088,7 @@
     sv_setiv (pDomTreeSV, r -> Component.xCurrDomTree) ;
     pCallerDomTree = DomTree_self (r -> Component.xCurrDomTree) ;
 
-    if (bSubNotEmpty)
+    if (bSubNotEmpty && r -> Component.xCurrNode)
         r -> Component.xCurrNode = xDocFraq = Node_insertAfter (r -> pApp, 
pSubDomTree, pSubDomTree -> xDocument, 0, pCallerDomTree, r -> 
Component.xCurrNode, r -> Component.nCurrRepeatLevel) ;
 
     if (r -> Component.Config.bDebug & dbgRun)

Modified: perl/embperl/trunk/test.pl
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/test.pl?rev=330373&r1=330372&r2=330373&view=diff
==============================================================================
--- perl/embperl/trunk/test.pl (original)
+++ perl/embperl/trunk/test.pl Wed Nov  2 14:00:14 2005
@@ -415,6 +415,9 @@
     'sub2.htm' => { 
         'repeat'     => 2,
         },
+    'subargs.htm' => { 
+        'repeat'     => 2,
+        },
     'subout.htm' => { 
         'repeat'     => 2,
         },

Added: perl/embperl/trunk/test/cmp/subargs.htm
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/test/cmp/subargs.htm?rev=330373&view=auto
==============================================================================
--- perl/embperl/trunk/test/cmp/subargs.htm (added)
+++ perl/embperl/trunk/test/cmp/subargs.htm Wed Nov  2 14:00:14 2005
@@ -0,0 +1,43 @@
+

+<html>

+<head>

+<title>Define a Subroutine with Args within Embperl</title>

+</head>

+

+<body>

+

+

+

+

+

+

+

+1,2->

+

+a=1
+b=2
+3,4->

+

+a=3
+b=4
+1,2->

+

+c=1 + 2 = 3
+3,4->

+

+c=3 + 4 = 7
+1,2->

+

+a=1

+b=2

+c=-1

+3,4->

+

+a=3

+b=4

+c=-1

+<P>Ok.<P>

+

+

+</body>

+</html>


Propchange: perl/embperl/trunk/test/cmp/subargs.htm
------------------------------------------------------------------------------
    svn:executable = *

Modified: perl/embperl/trunk/test/conf/httpd.conf.src
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/test/conf/httpd.conf.src?rev=330373&r1=330372&r2=330373&view=diff
==============================================================================
--- perl/embperl/trunk/test/conf/httpd.conf.src (original)
+++ perl/embperl/trunk/test/conf/httpd.conf.src Wed Nov  2 14:00:14 2005
@@ -151,6 +151,7 @@
 print OFH <<EOD ;
 
 Embperl_Cookie_Path /
+Embperl_Cookie_Expires "+1d"
 EMBPERL_ALLOW (asc|\\.xml\$|\\.htm\$)
 
 

Added: perl/embperl/trunk/test/html/subargs.htm
URL: 
http://svn.apache.org/viewcvs/perl/embperl/trunk/test/html/subargs.htm?rev=330373&view=auto
==============================================================================
--- perl/embperl/trunk/test/html/subargs.htm (added)
+++ perl/embperl/trunk/test/html/subargs.htm Wed Nov  2 14:00:14 2005
@@ -0,0 +1,55 @@
+

+<html>

+<head>

+<title>Define a Subroutine with Args within Embperl</title>

+</head>

+

+<body>

+

+[$ sub test ($a, $b) $]

+

+a=[+ $a +]

+b=[+ $b +]

+

+[$endsub$]

+

+

+[$ sub test2 ($a, $b) 

+

+$c = $a + $b ;

+

+$]

+

+c=[+ $a +] + [+ $b +] = [+ $c +]

+

+[$endsub$]

+

+

+[$ sub test3 ($a, $b) 

+

+my $c = ($a - $b) ;

+

+$]

+

+a=[+ $a +]

+b=[+ $b +]

+c=[+ $c +]

+

+[$endsub$]

+

+

+

+1,2->[- test(1,2) -]

+3,4->[- test(3,4) -]

+

+1,2->[- test2(1,2) -]

+3,4->[- test2(3,4) -]

+

+1,2->[- test3(1,2) -]

+3,4->[- test3(3,4) -]

+ 

+<P>Ok.<P>

+

+

+</body>

+</html>


Propchange: perl/embperl/trunk/test/html/subargs.htm
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to