Re: : Yet more code (Was: Re: A nifty code sample to share)

2002-09-26 Thread Josh Chamas

[EMAIL PROTECTED] wrote:
 Hi Josh ,
 
 my $xml_data;
 $xsl_data = Test.xsl;
 $xml_data = Test.xml;
 my $xslt_data_ref = $Server-XSLT(\$xsl_data, \$xml_data);
 print $$xslt_data_ref;
   

$xsl_data  $xml_data need to be strings, not filenames, as in:

open(XML, 'Test.xml') || die(can't open: $!);
my $xml_data = join('', XML);
close XML;
...


 
#
  It errors out with the error as though it is implictly using XML::XSLT
 
###
 failed to load XML::XSLT 0.32: Can't locate XML/XSLT.pm in @INC (@INC contains: 
/home/nalamara/myapache/htdocs/asp/eg//. 
/sbcimp/run/pd/apache_modules/1.3.19/mod_perl/1.25+perl-5.005_03/lib/sun4-solaris 
/sbcimp/run/pd/apache_modules/1.3.19/mod_perl/1.25+perl-5.005_03/lib 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib 
/sbcimp/run/pd/cpan/5.6.1-2002.06/lib /sbcimp/run/pd/perl/5.005_03/lib/sun4-solaris 
/sbcimp/run/pd/perl/5.005_03/lib 
/sbcimp/run/pd/perl/5.005_03/lib/site_perl/sun4-solaris 
/sbcimp/run/pd/perl/5.005_03/lib/site_perl . /sbcimp/run/pd/apache/1.3.19/ 
/sbcimp/run/pd/apache/1.3.19/lib/perl) at (eval 43) line 3. BEGIN failed--compilation 
aborted at (eval 43) line 3. , 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/Apache/ASP.pm 
line 1556 
 
###
   

You also need to set XSLTParser set to XML::LibXSLT
Please see http://www.apache-asp.org/config.html#XSLTParser
for more information.

Regards,

Josh

Josh Chamas, Founder   phone:925-552-0128
Chamas Enterprises Inc.http://www.chamas.com
NodeWorks Link Checkinghttp://www.nodeworks.com


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




RE: : Yet more code (Was: Re: A nifty code sample to share)

2002-09-24 Thread Raghu . Nalamada

Hi Josh ,

 Thanks for your help . Atlast Resolved XSLT error , I had to include 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run//pd/libxslt/1.0.20/lib in 
LD_LIBRARY_PATH.

 I generate XML from SQL using perl module XML_RDB . Using Apache::ASP i like 
to display the output depending upon xsl choosen.

 As you have indicated below can i use something like 

$Server-Config(Test.xml)
and
$Server-Config(Test.xml)

The name of the xml file generated would be different according to choices 
made . Not sure what the syntax
should be in calling the XML file .

Regards

Raghu
-Original Message-
From: Josh Chamas [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 23, 2002 8:09 PM
To: Nalamada, Raghu
Cc: [EMAIL PROTECTED]
Subject: Re: : Yet more code (Was: Re: A nifty code sample to share)


[EMAIL PROTECTED] wrote:
 Hi Josh,
 
 I need to add to different xsl file depending upon the user's request  .
 

I believe the $Server-Config() method that I mentioned should work for you.

 Yes LibXSLT is installed , When i add to httpd.conf it gives me the error
 
 
#
 Syntax error on line 675 of httpd.conf:
 Can't load 
'/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/auto/XML/LibXML/LibXML.so'
 for module XML::LibXML: ld.so.1: /sbcimp/run/pd/apache/1.3.19/bin/httpd: fatal: 
libxml2.so.2: open failed: No such file or directory at 
/sbcimp/run/pd/perl/5.005_03/lib/sun4-solaris/DynaLoader.pm line 169.
 at 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/XML/LibXSLT.pm 
line 8
 BEGIN failed--compilation aborted at 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/XML/LibXSLT.pm 
line 8.
 

You need to get XML::LibXSLT installed such that it will load correctly
via a PerlModule directive and also a command like:

   perl -MXML::LibXSLT -e ''

Make sure that the location of the libxml2 is found correctly
in your system LD_LIBRARY_PATH.

Regards,

Josh

Josh Chamas, Founder   phone:925-552-0128
Chamas Enterprises Inc.http://www.chamas.com
NodeWorks Link Checkinghttp://www.nodeworks.com


Visit our website at http://www.ubswarburg.com

This message contains confidential information and is intended only
for the individual named.  If you are not the named addressee you
should not disseminate, distribute or copy this e-mail.  Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses.  The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission.  If
verification is required please request a hard-copy version.  This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.


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




Re: : Yet more code (Was: Re: A nifty code sample to share)

2002-09-24 Thread Josh Chamas

[EMAIL PROTECTED] wrote:
 Hi Josh ,
 
  Thanks for your help . Atlast Resolved XSLT error , I had to include 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run//pd/libxslt/1.0.20/lib in 
LD_LIBRARY_PATH.
 
  I generate XML from SQL using perl module XML_RDB . Using Apache::ASP i 
like to display the output depending upon xsl choosen.
 
  As you have indicated below can i use something like 
 

Use $Server-Config('XSLT', 'test.xsl') to change the XSL document
at runtime.

If you have some arbitrary XML  XSL that you want to transform,
you may use $Server-XSLT() method, and just pass in the raw data.
Please see http://www.apache-asp.org/objects.html#%24Server-%3EXSL7df794aa
for more about this method.

 The name of the xml file generated would be different according to choices 
made . Not sure what the syntax
 should be in calling the XML file .

The normal way the XSLT tranformation is done is the output of the
ASP script is treated as the source XML, and then you specifiy the
XSL file with the XSLT config parameter.  The idea here was that
you could have a global XSL renderer  each of your ASP scripts
would act as the source XML data, so that in fact your ASP scripts
could even be literally source XML data.

Regards,

Josh

Josh Chamas, Founder   phone:925-552-0128
Chamas Enterprises Inc.http://www.chamas.com
NodeWorks Link Checkinghttp://www.nodeworks.com


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




: Yet more code (Was: Re: A nifty code sample to share)

2002-09-23 Thread Raghu . Nalamada

Hi All ,

 Is there any way in Apache::ASP to dynamically give a XSL file rather setting 
to default like template.xsl in .htaccess file as given in eg directory.

 Also iam seem to be having erros when using LIBXSLT
XSLT/XML processing error: Can't locate object method new via package XML::LibXSLT 
at /Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/Apache/ASP.pm 
line 1718. , 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/Apache/ASP.pm 
line 3817 

Seem to be having a problem in the line
my $xslt = XML::LibXSLT-new();

 Any pointers what iam doing wrong would be very helpful.

Thanks
Raghu



-Original Message-
From: Josh Chamas [mailto:[EMAIL PROTECTED]]
Sent: Saturday, September 21, 2002 2:52 PM
To: Brat Wizard
Cc: Apache::ASP Mailing List
Subject: Re: Yet more code (Was: Re: A nifty code sample to share)


Brat Wizard wrote:
 
 Josh- why not make it a simple directive, like a pragma-- then it could be 
 specified inline by the end-user whenever (and if-ever) they need it one way 
 or the other.
 
 Perhaps something like:
 
 $Apache::ASP::XMLSubsPostProc = 1


Right.  I would never take away the current style/method of XMLSubs,
just add to it like you suggest.

 my:sub
   my:nestedsub%=$blech% __TOKEN1__/my:nestedsub
   %=$foobar% __TOKEN2__
 /my:sub
 
 You could wait until after the first my:sub had been called to interpret the 
 rest-- just process everything post. In my thinking __TOKEN1__ and __TOKEN2__ 
 would get resolved by the renderer function on the first pass and 
 my:nestedsub, $blech, and $foobar, would get processed immediately 
 afterwards-- after the tokens had been substituted.
 
 How would that work out do you think?


So then the parent XMLSubs output would be then evaluated
at runtime as ASP script automatically by the system.  That
is an interesting way of looking at doing the pre-processing.

The only problem with this model is that runtime parsing/eval
of the code would be expensive.  The other preprocessing model
that I was considering would not do ANY inner code substitution
on its own, leaving this to the XMLSubs definition to do if
it wanted to.

I am not sure which one I would lean to more, but they are both
interesting models.

my $pgimage = My::PgImage-new(
  ASP = $asp,
  Attrib = { pg=__PG__ sku=__SKU__ },
  Parent = $pgloop
};
$pgimage-execute(\'');
$pgloop-execute(\$final_data_output_within);
 
 
 
This pre/post processing model would allow pgimage to
work with $self-{Parent}{sth}, or pgloop could populate
its own data in this way.  Output from pgimage could be
trapped and inlined, passed into the execute() function
for pgloop.
 
 
 Hmm- sounds a little complicated. Not to mention you are exposing a lot of the 
 $asp guts to the programmer/user that way and the goal should be the exact 
 opposite-- to abstract that away from the programmer and toward the 
 web-monkey/end-user...?
 


This was just an example of how the preprocessing model would
get executed.  This would be more for the XMLSubs definer to
worry about.  I ideally to the end user, things would just work.
I believe that XMLSubs will have to grow in complexity to be
able to do really doo things that other platform taglib functionality
offers.  I will be looking hard as JSP  AxKit before I do any
next generation XMLSubs for sure.

 
 Actually I was thinking something very similar but for another reason-- if you 
 use delayed processing, like I describe above, conditionals actually get 
 pretty easy I think. You just build them into the my:sub $body text and let 
 the post-processing pick them up.


I see the power of the preprocessing + execute output during post
processing model.  The speed issue is the only one I have to get
over here.  I'll look at some taglib libraries that I would like
to implement in Apache::ASP  see what kind of power we need here.
It may be that some things are only possible with the kind of
power that you suggest, and its a very interesting idea giving
the XMLSubs programmer the ability to rewrite the code on the fly.

 All you need to do is make the one adjustment to handle % % subs post 
 instead of pre and I think the render function can handle the inbetween 
 stuff. The __TOKEN__ format is very comfortable and intuitive to me in this 
 instance. It seems very obvious that they are serving as placeholders for 
 yet-to-be-in-scope data. And by delaying the % % processing, you allow 
 substitution to occur _before_ conditional blocks take place.
 
 
 What is your take on all this? 
 
 I think we've just descibed a very functional, useable processing paradigm 
 that fits with the current feel of the asp system, and with the single 
 exception of moving % % substitution to post-processing, you don't have to 
 make any other radical changes to the Apache::ASP framework or api (at least 
 I don't think you do).
 
 Your thoughts?
 

Pretty good stuff.  I'll definately be following up on this later

RE: : Yet more code (Was: Re: A nifty code sample to share)

2002-09-23 Thread Raghu . Nalamada

Hi Josh,

I need to add to different xsl file depending upon the user's request  .

Yes LibXSLT is installed , When i add to httpd.conf it gives me the error

#
Syntax error on line 675 of httpd.conf:
Can't load 
'/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/auto/XML/LibXML/LibXML.so'
 for module XML::LibXML: ld.so.1: /sbcimp/run/pd/apache/1.3.19/bin/httpd: fatal: 
libxml2.so.2: open failed: No such file or directory at 
/sbcimp/run/pd/perl/5.005_03/lib/sun4-solaris/DynaLoader.pm line 169.
at /Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/XML/LibXSLT.pm 
line 8
BEGIN failed--compilation aborted at 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/XML/LibXSLT.pm 
line 8.

Thanks

Raghu


-Original Message-
From: Josh Chamas [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 23, 2002 4:21 PM
To: Nalamada, Raghu
Cc: [EMAIL PROTECTED]
Subject: Re: : Yet more code (Was: Re: A nifty code sample to share)


[EMAIL PROTECTED] wrote:
 Hi All ,
 
  Is there any way in Apache::ASP to dynamically give a XSL file rather 
setting to default like template.xsl in .htaccess file as given in eg directory.
 

Try:

   $Server-Config('XSLT', 'filename');

you could add this to Script_OnStart global.asa for example.

  Also iam seem to be having erros when using LIBXSLT
 XSLT/XML processing error: Can't locate object method new via package 
XML::LibXSLT at 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/Apache/ASP.pm 
line 1718. , 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/Apache/ASP.pm 
line 3817 
 

Do you have XML::LibXSLT installed?  Does it help if you add

   PerlModule XML::LibXSLT

to your apache httpd.conf ?  Can you get XML::XSLT or
XML::Sablotron to work as your XSLTParser, and just not
XML::LibXSLT ?

Regards,

Josh


Josh Chamas, Founder   phone:925-552-0128
Chamas Enterprises Inc.http://www.chamas.com
NodeWorks Link Checkinghttp://www.nodeworks.com


Visit our website at http://www.ubswarburg.com

This message contains confidential information and is intended only
for the individual named.  If you are not the named addressee you
should not disseminate, distribute or copy this e-mail.  Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses.  The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission.  If
verification is required please request a hard-copy version.  This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.


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




Re: : Yet more code (Was: Re: A nifty code sample to share)

2002-09-23 Thread Josh Chamas

[EMAIL PROTECTED] wrote:
 Hi Josh,
 
 I need to add to different xsl file depending upon the user's request  .
 

I believe the $Server-Config() method that I mentioned should work for you.

 Yes LibXSLT is installed , When i add to httpd.conf it gives me the error
 
 
#
 Syntax error on line 675 of httpd.conf:
 Can't load 
'/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/auto/XML/LibXML/LibXML.so'
 for module XML::LibXML: ld.so.1: /sbcimp/run/pd/apache/1.3.19/bin/httpd: fatal: 
libxml2.so.2: open failed: No such file or directory at 
/sbcimp/run/pd/perl/5.005_03/lib/sun4-solaris/DynaLoader.pm line 169.
 at 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/XML/LibXSLT.pm 
line 8
 BEGIN failed--compilation aborted at 
/Net/stmdvocs/sbcexp/devl/SunOS/sparc-5.6/run/pd/cpan/5.6.1-eval/lib/XML/LibXSLT.pm 
line 8.
 

You need to get XML::LibXSLT installed such that it will load correctly
via a PerlModule directive and also a command like:

   perl -MXML::LibXSLT -e ''

Make sure that the location of the libxml2 is found correctly
in your system LD_LIBRARY_PATH.

Regards,

Josh

Josh Chamas, Founder   phone:925-552-0128
Chamas Enterprises Inc.http://www.chamas.com
NodeWorks Link Checkinghttp://www.nodeworks.com


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




Re: Yet more code (Was: Re: A nifty code sample to share)

2002-09-22 Thread Brat Wizard


Of course, you could also put just the info to be included into a separate 
file and allow it to be included at a judicious moment... (nah, that would be 
too easy ;)

But the one thing that _doesn't_ allow for, and the reason why I myself have 
been working on the problem-- is putting together something you can let the 
end-user (the buyer of the account) create/customize/or otherwise abuse w/o 
worrying about compromising the sanctity of the system in the process. They 
can only supply tokens to be substituted and simple formatting directives, 
and not actualy code (although the ()?: structure I presented does allow 
actual code to be executed, something I would have to deal with somehow).



 I see the power of the preprocessing + execute output during post
 processing model.  The speed issue is the only one I have to get
 over here.

-- 


Check out http://www.Wizard.Org for great deals on Electronic Parts
*NEW* Computer Parts  Accessories - Drives - LCD - Systems - Linux

** Affordable Online Store w/Merchant Card Processing  Paypal **
Write to us: [EMAIL PROTECTED]  --  Get your Store Online Today!




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




Re: Yet more code (Was: Re: A nifty code sample to share)

2002-09-21 Thread Brat Wizard


A follow-up to my last post... adding this line to the render func:

$tmpl =~ s/__\((.*?)\)__/%=($1)%/gm; # fixup embedded tests

Allows this construct to be used:

__(__F_ONSALE__?'YES':'NO')__

These constructs also work as expected:

Item on sale? Yes or No:
__(__F_ONSALE__?'YES':'NO')__

Item NOT on sale? Yes or No:
__(!__F_ONSALE__?'YES':'NO')__

Price  5? Yes or No
__(__AMT_PRICE__5?'YES':'NO')__

Item on Sale? Sale Price or Reg Price:
__(__F_ONSALE__?__AMT_SALE__:__AMT_PRICE__)__

Here is the complete render func to date:

sub render { ## process a body-template string and render appropriately
my ($tmpl, $hash, $fmt) = @_;
$tmpl =~ s/__\[(.*?)\]__/$1/gm; # fixup delayed-embedded xmlsubs
$tmpl =~ s/__\((.*?)\)__/%=($1)%/gm; # fixup embedded tests
while ($tmpl =~ /__(.*?)__/) {
my $TOKEN = $1; my $token = lc($TOKEN);
if ((my $fmt = $$fmt{$TOKEN}) ne undef) {
# to-uppercase
if ($fmt =~ /^%uc/i) { $fmt =~ s/[^0-9]//gm; 
$$hash{$tok
en} = uc(substr($$hash{$token}, 0, $fmt || length($$hash{$token}))); }
# to-lowercase
elsif ($fmt =~ /^%lc/i) { $fmt =~ s/[^0-9]//gm; 
$$hash{$
token} = lc(substr($$hash{$token}, 0, $fmt || length($$hash{$token}))); }
# picture
else { $$hash{$token} = sprintf($fmt, $$hash{$token}); 
}
}
$tmpl =~ s/__${TOKEN}__/$$hash{$token}/gme;
}
$Response-Include(\$tmpl);
}

__END__


This is getting cool :) 

John





-- 


Check out http://www.Wizard.Org for great deals on Electronic Parts
*NEW* Computer Parts  Accessories - Drives - LCD - Systems - Linux

** Affordable Online Store w/Merchant Card Processing  Paypal **
Write to us: [EMAIL PROTECTED]  --  Get your Store Online Today!






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




Re: Yet more code (Was: Re: A nifty code sample to share)

2002-09-20 Thread Brat Wizard

Yes, but extrordinarily easy-to-do and it didn't break nuthin ;)


On Friday 20 September 2002 02:27 pm, you muttered:
 Brat Wizard wrote:
  # picture
  else { $$hash{$token} = sprintf($fmt,
  $$hash{$token}); }
  }
  $tmpl =~ s/__${TOKEN}__/$$hash{$token}/gme;
  }
  $Response-Include(\$tmpl);
  }

 Now that is interesting.  You grabbed all the raw output, preprocessed
 it, and then ran executed it again, effectively creating a preprocessing
 model.  Tricky.  This gives something to think about...

 --Josh
 
 Josh Chamas, Founder   phone:925-552-0128
 Chamas Enterprises Inc.http://www.chamas.com
 NodeWorks Link Checkinghttp://www.nodeworks.com

-- 


Check out http://www.Wizard.Org for great deals on Electronic Parts
*NEW* Computer Parts  Accessories - Drives - LCD - Systems - Linux

** Affordable Online Store w/Merchant Card Processing  Paypal **
Write to us: [EMAIL PROTECTED]  --  Get your Store Online Today!




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




Re: Yet more code (Was: Re: A nifty code sample to share)

2002-09-20 Thread Brat Wizard



 Right, its almost as if one would want a pre-processing stage of not the
 output, but of the content.  The current model was not built to be easily
 extendable to this as there is only one sub per XMLSubs that gets called,
 but what you would really want is something like:

 sub my::sub_pre()
 sub my::sub_post()

Josh- why not make it a simple directive, like a pragma-- then it could be 
specified inline by the end-user whenever (and if-ever) they need it one way 
or the other.

Perhaps something like:

$Apache::ASP::XMLSubsPostProc = 1

(or whatever)

And that would indicate to the system that it should enter post-processing 
mode. That way you would stay compatible with current code but allow the 
ability to be turned on/off as/if needed.

However, in thinking it through-- generally-speaking (while maybe not true in 
every case, for most cases it would be)-- things that would get substituted a 
la % % prior to calling the first my:sub are still available to be 
substituted afterwards as long as you get back to the original scope-context. 
I'm trying to think of a situation where it would be disadvantageous to delay 
substitution... nothing springs to mind right off but I don't want to say 
never either.

So if you had, say:

my:sub
  my:nestedsub%=$blech% __TOKEN1__/my:nestedsub
  %=$foobar% __TOKEN2__
/my:sub

You could wait until after the first my:sub had been called to interpret the 
rest-- just process everything post. In my thinking __TOKEN1__ and __TOKEN2__ 
would get resolved by the renderer function on the first pass and 
my:nestedsub, $blech, and $foobar, would get processed immediately 
afterwards-- after the tokens had been substituted.

How would that work out do you think?


 Unfortunately, any parsing of this script is quite likely to thrown lines
 numbers off from the original source.

Yeah well, life sucks don't it ;)

If it really bothered you, you could always make a note in the output that the 
line numbering might be off.


 Another mechanism for might be good to use for this is to use ASPish
 global.asa events that can be called every XMLSubs execution, both
 before  after, like:

 sub XMLSubs_OnStart {
 my($xml_tag_name, $args, $html_input) = @_;
 }

 sub XMLSubs_OnEnd {
 my($xml_tag_name, $args, $html_output) = @_;
 }

This doesn't seem like a very clean solution to me, a kludge at best. If you 
don't mind my saying so, I think my solution is better using the rendering 
function I put forth. Its also easier and works out-of-the-box with no 
additional modification. 

Just delay the % % substitution until after the initial rendering stage and 
let post-processing pick it up-- the only minor hitch is that you need to 
make sure you're back in the original scope before doing the substitution. 
__TOKENS__ get replaced inside the my:sub function, by the my:sub function-- 
whether with the render function or directly by the programmer-- and % % 
get replaced immediately after its return.


 In an OO model, I think we could achieve something like this as in:

 my $pgloop = My::Pgloop-new(
   ASP = $asp,
   Attrib = { sth = $sth },
   Content = \$data_within,
 };
 my $pgimage = My::PgImage-new(
   ASP = $asp,
   Attrib = { pg=__PG__ sku=__SKU__ },
   Parent = $pgloop
 };
 $pgimage-execute(\'');
 $pgloop-execute(\$final_data_output_within);


 This pre/post processing model would allow pgimage to
 work with $self-{Parent}{sth}, or pgloop could populate
 its own data in this way.  Output from pgimage could be
 trapped and inlined, passed into the execute() function
 for pgloop.

Hmm- sounds a little complicated. Not to mention you are exposing a lot of the 
$asp guts to the programmer/user that way and the goal should be the exact 
opposite-- to abstract that away from the programmer and toward the 
web-monkey/end-user...?


  Another useful thing might be a def field (define) field that could
  construct artificial tokens based on expression-manipulation of existing
  data available in the dataset at time of rendering. That way you could
  have a cost field and apply a markup value to it and come up with an
  artificial, but usable price token.
 
  my:sub
definePRICE:COST*1.2/define
   The cost of this item is __COST__ and it is currently selling for
  __PRICE__. /my:sub

 If we have a preprocessing stage like above, 

That is really a weak example actually. And after thinking about it awhile, I 
think I agree with you that having define blocks is a bad idea. While it 
might be useful to have that sort of flexibility, in reality it would be a 
bad idea to depend on a number hard-coded into the html body to define the 
markup value of the price (to use the example)-- and might encourage 
programmers (who oughta know better) to do silly things.



In my own project that I'm currently working on-- I have two major issues (at 
least as bounded by the context of this discussion and in trying to resolve 
it using tools developed herein)-- and they are:


Re: A nifty code sample to share

2002-09-18 Thread Josh Chamas

 my:sub ...
 fmtCOST:%.2f,AGE:%3d,STATE:%uc2/fmt
 This item costs __COST__ and you must be __AGE__ years old to buy it in the 
 state of __STATE__
 /my:sub
 

Assuming that the data is available when the my:sub is starting
to get processed, then you can use more XMLSubs to do your dirty work like:

% my $data_ref = \%data_hash; %
my:sub data=$data_ref
my:value name='COST' fmt='%.2f' /
my:value name='STATE' fmt='%uc2' /
/my:sub

That is at least how I would try to do it.

If you can end up with your document written entirely in XML,
then you are on your way to having your data written entirely
separately from your style, which is a good goal.  This is
the XML/XSLT paradigm, but can be implemented with XHTML,
XMLSubs, XSLT, you pick your favorite.

 B) The second issue is harder though and I still haven't thunk up a good 
 solution for it yet... and that is how to handle combined or calculated 
 post-processed fields-- ie
 
 my:sub ...
 __VAR1__ times __VAR2__ = [product here somehow??]
 /my:sub
 

Be careful... you are creating your own mini language here.
You could do this instead:

% my $data_ref = \%$data_hash; %
my:sub
   %= $data_ref-{VAR1} * $data_ref-{VAR2} %
/my:sub

I caution against going down the create your own mini language
path because it will end up being a language that only you know.
I would recommend more that if you want to inline a mini language,
that you look into rendering inline a bit of a template toolkit
or HTML::Template into your Apache::ASP, so you might have:

my:tt data=$data
   Template Toolkit mini language processed here
   You could then init the template with $data for parameters
/my:tt

At least TT or HTML::Template are already widely used, and would
suggest you go down that path for extending your Apache::ASP framework.

 While this may seem to get a little convoluted, there are some good reasons 
 why you would want this-- for example, say you have a flag and you need to 
 calculate something one way if it is set and another way if it isn't-- but 
 you don't know until after (or during) the post-processing takes place. I 
 guess perhaps there is a limit to how much one can cram into this XMLSubs 
 thing... ;)

There is a limit, but I would like to break it.  I believe I can add
a lot of power to XMLSubs, if I allow them to also be called at
compile time as an extension, so that the ASP template being compiled
could be modified instead of the output.  The runtime model has more
limits, and the compile time model would only be added as an extension.
I have been mulling these kinds of extensions to XMLSubs for a while,
so do not hold your breath.

 
 Hmm -- what I do now is very close to what you're describing but not taking 
 the one last step of pulling the actual application itself into an object 
 model. I use the Script_OnStart to instantiate several objects but end up 
 passing them around using global vars that I then have to keep up with. If 
 I'm understanding you correctly, this is a subtle paradigm shift for me that 
 shoves the application out of view and into its own application object class 
 which the html files (asp files) within that application domain automagically 
 get the benefit of (through instantiation in the Script_OnStart method of the 
 global.asa) Which then means that they can access all of the application data 
 via the application object, and the various application-level methods again 
 via the object (which is not to be confused with the official $Application 
 object that is already a part of Apache::ASP). So the details of 
 instantiation of the application object are effectively obscured from the 
 final html renderer file-- the view as it were...
 

Yep.

 Thanks for clearing that up. I understand its purpose now. What I've been 
 doing hasn't been wrong or even ineffective, I just haven't been taking 
 full advantage of the one last level of abstraction that's potentially 
 available to me. Hmm-- I think I'm going to enjoy exploring this further.
 

Right.  The more you get into this stuff, the more effective you become.
Its pretty neat because you can constantly learn how to do things better.
I do all the time, even with Apache::ASP. :)

 
 So what you're saying is that _technically_ this would not be the place to put 
 (say) html rendering routines, but that _some_ html rendering routines are so 
 fundamental and basic, they might as well be in here? For example, you might 
 have a counter object where, in purity, you would not want to dictate any 
 particular rendering, but because it is used primarily (and almost 
 exclusively) as an html adjunct component, you might want to include a 
 'renderHtml' (or whatever) method that breaks the paradigm a little...?
 

Right.  Technically, I think you need to have view objects doing
view things specific to the rendering platform ( HTML ), separate
from the model/App object.  Theoretically the App object should be just
as useful in a Tk GUI view renderer as it is with an HTML 

A nifty code sample to share

2002-09-17 Thread Brat Wizard


I've been meaning for a long time to release some code samples-- here is one I 
especially like for making menus and navbars in html-- same code will work 
for either.

A caveat: I use several custom modules which hides some stuff- most notably 
the Page object, which is basically a hash of hashes that contain the 
menu-item data, as well as an array of pages (items in a Page object) which 
keeps the correct page-order. The general structure of a page-item is like 
this:

name= undef,   # name of page item (eg. 'contact')
admin   = 0,   # 1=Admin-Only
caption = undef,   # page caption (eg. Contact Us)
url = undef,   # what to do if clicked eg: http://someurl
type= 'user',  # User or Prot (Prot=protected  can't edit)
origin  = 'user',  # User or Int (Int=internal)
active  = 0, # mark inactive by default

And not all of these items are relevant to this routine. So, that said, this 
snippet of code-- which is meant more for its idea value than its particular 
usefulness as written-- (it works well in my apps but you won't have all the 
supporting stuff to make it work out of the box). This bit of code will allow 
you to very easily specify an html menu/navbar structure and have the 
selected item behave differently, and to specify the menu separator (if any). 
It easily lends itself to horizontal and vertical menus and its html-like 
(xml-ish) syntax is like so (a simplified vertical example):

tabletrtd
my:menu selected=$$args{cmd}
   selba href=__URLCAPTION__/a/bbr/sel
  norma href=__URLCAPTION__/abr/norm
/my:menu
/td/tr/table

This produces a very attractive (albeit simple) vertical menu. What's 
important is to notice the sel, norm, and (if present), sep tags (and 
they need to be closed). ANY legal html/javascript code (or anything else for 
that matter that can be expressed as a string) can be put between the tags. 
For example, in more complicated menus, I often use javascript to do button 
rollover effects and the like. 

The function presented below will take everything (in uppercase) surrounded by 
two underscores (ie. '__FIELD__') and attempt to match it to its 
corresponding (lower-case) field in the page-item object (or your own 
substituted hash structure). 

If the sep tag is present, it will be used between the menu/navbar items and 
will separate the items however you say. I often just use something like 
sep|/sep (vertical bar) or sepnbsp;nbsp;/sep (a couple of spaces), 
but it can be anything html.

To make this work, you have to be using the XMLSubsMatch setting in the 
.htaccess or apache config file (wherever you set your other ASP config 
vars). Mine looks like this: 

   PerlSetVar XMLSubsMatch my:\w+

This causes anything beginning with 'my:' in my .html/.asp files to be 
interpreted (or attempted anyway) as a sub-routine reference. The args 
supplied inside the opening tag itself are passed to the subroutine as 
'$args' (or whatever you want to call it-- the first argument passed). The 
text (if any) between the tags is passed as the second ($body).  Such that:

my:parseme somefield=someval
Whatever you want to pass as the body goes here
/my:parseme

This is all documented better on the main ASP site.

One thing to note that is NOT mentioned on the ASP site-- apparently the 
parsing algorithm doesn't know how to handle values that are NOT enclosed in 
quotes. Html does not require quotes as long as the value contains no spaces 
and only alphanumeric characters. You can't do that here. The other thing to 
point out is that any perl variables (eg. $myvar) are NOT escaped in the 
usual apache::asp way, (%=$myvar%) but instead are just simply passed 
between the quotes. Personally I think this is an inconsistancy, and one that 
should be dealt with so that clueless users who write html pages using custom 
tags don't accidently expose the workings of apache::asp. An alternative 
might be to allow a secondary syntax that could only be used as subroutine 
references-- eg. [% stuff %]. I can understand the depth of the syntax and 
coding problems surrounding this issue-- especially when the subject of 
nesting comes up... I'm not complaining, just tossing in my 2 cents and 
wishing there was a way to keep the functional aspect without exposing ASP to 
the clueless user (or malicious web hacker for that matter).

Anyway, fwiw, here is the routine below. You can see an example of it in 
operation at: stores.wizard.org/wizorg, stores.wizard.org/wizcomp, and 
stores.wizard.org/dots (I'm not sure that Dot has her store completely set up 
and ready to go but you can see the menu anyway).

I hope this helps someone! :)

John Whitten
[EMAIL PROTECTED]
Wizard.Org, Inc.


##
sub my::navbar { my::menu(@_) }
sub my::menu {
my ($args, $body) = @_;
my $norm = qq{a 

Re: A nifty code sample to share

2002-09-17 Thread Brat Wizard

Um- minor correction-

I slightly misspoke-- I was confusing this with another module I have. This 
example _only_ matches the URL, CAPTION, and NAME fields from the hash. Sorry 
for any confusion.

John


On Tuesday 17 September 2002 03:27 am, Brat Wizard spewed into the ether:
 I've been meaning for a long time to release some code samples-- here is
 one I especially like for making menus and navbars in html-- same code will
 work for either.

 A caveat: I use several custom modules which hides some stuff- most notably
 the Page object, which is basically a hash of hashes that contain the
 menu-item data, as well as an array of pages (items in a Page object) which
 keeps the correct page-order. The general structure of a page-item is like
 this:

 name= undef,   # name of page item (eg. 'contact')
 admin   = 0,   # 1=Admin-Only
 caption = undef,   # page caption (eg. Contact Us)
 url = undef,   # what to do if clicked eg: http://someurl
 type= 'user',  # User or Prot (Prot=protected  can't
 edit) origin  = 'user',  # User or Int (Int=internal)
 active  = 0, # mark inactive by default

 And not all of these items are relevant to this routine. So, that said,
 this snippet of code-- which is meant more for its idea value than its
 particular usefulness as written-- (it works well in my apps but you won't
 have all the supporting stuff to make it work out of the box). This bit of
 code will allow you to very easily specify an html menu/navbar structure
 and have the selected item behave differently, and to specify the menu
 separator (if any). It easily lends itself to horizontal and vertical menus
 and its html-like (xml-ish) syntax is like so (a simplified vertical
 example):

 tabletrtd
 my:menu selected=$$args{cmd}
selba href=__URLCAPTION__/a/bbr/sel
   norma href=__URLCAPTION__/abr/norm
 /my:menu
 /td/tr/table

 This produces a very attractive (albeit simple) vertical menu. What's
 important is to notice the sel, norm, and (if present), sep tags (and
 they need to be closed). ANY legal html/javascript code (or anything else
 for that matter that can be expressed as a string) can be put between the
 tags. For example, in more complicated menus, I often use javascript to do
 button rollover effects and the like.

 The function presented below will take everything (in uppercase) surrounded
 by two underscores (ie. '__FIELD__') and attempt to match it to its
 corresponding (lower-case) field in the page-item object (or your own
 substituted hash structure).

 If the sep tag is present, it will be used between the menu/navbar items
 and will separate the items however you say. I often just use something
 like sep|/sep (vertical bar) or sepnbsp;nbsp;/sep (a couple of
 spaces), but it can be anything html.

 To make this work, you have to be using the XMLSubsMatch setting in the
 .htaccess or apache config file (wherever you set your other ASP config
 vars). Mine looks like this:

PerlSetVar XMLSubsMatch my:\w+

 This causes anything beginning with 'my:' in my .html/.asp files to be
 interpreted (or attempted anyway) as a sub-routine reference. The args
 supplied inside the opening tag itself are passed to the subroutine as
 '$args' (or whatever you want to call it-- the first argument passed). The
 text (if any) between the tags is passed as the second ($body).  Such that:

   my:parseme somefield=someval
   Whatever you want to pass as the body goes here
   /my:parseme

 This is all documented better on the main ASP site.

 One thing to note that is NOT mentioned on the ASP site-- apparently the
 parsing algorithm doesn't know how to handle values that are NOT enclosed
 in quotes. Html does not require quotes as long as the value contains no
 spaces and only alphanumeric characters. You can't do that here. The other
 thing to point out is that any perl variables (eg. $myvar) are NOT escaped
 in the usual apache::asp way, (%=$myvar%) but instead are just simply
 passed between the quotes. Personally I think this is an inconsistancy, and
 one that should be dealt with so that clueless users who write html pages
 using custom tags don't accidently expose the workings of apache::asp. An
 alternative might be to allow a secondary syntax that could only be used as
 subroutine references-- eg. [% stuff %]. I can understand the depth of the
 syntax and coding problems surrounding this issue-- especially when the
 subject of nesting comes up... I'm not complaining, just tossing in my 2
 cents and wishing there was a way to keep the functional aspect without
 exposing ASP to the clueless user (or malicious web hacker for that
 matter).

 Anyway, fwiw, here is the routine below. You can see an example of it in
 operation at: stores.wizard.org/wizorg, stores.wizard.org/wizcomp, and
 stores.wizard.org/dots (I'm not sure that Dot has her store completely set
 up and ready to go but you 

Re: A nifty code sample to share

2002-09-17 Thread Josh Chamas


I've been meaning for a long time to release some code samples-- here is
one I especially like for making menus and navbars in html-- same code will
work for either.


I have created the ability in the system to have includes shared
pretty easily with the Share:: namespace, but haven't put anything
in there yet.  This namespace is Apache::ASP::Share more generally,
so this could then a module like Apache::ASP::Share::Wizard,
which might export a menu() subroutine, that someone could then
wire pretty easily into their XMLSubs package namespace?
Then this sub could be distributed with Apache::ASP.

Alternatively, you could publish this to CPAN as the
Apache::ASP::Share::Wizard package, and put everything you
want in there at your leisure.  Useful templates can be loaded
from that like $Response-Include(Share::Wizard/template.inc),
and the subs/objects can be imported normally.  That would
be cool if at the end of an install, someone could
man/perldoc Apache::ASP::Share::Wizard

I wish I had a better structured interface for this, or
a XMLSubs namespace mapping ability, but I have neither yet
hooked into Apache::ASP.  The Share:: include namespace
was hard enough to work out as it was.

tabletrtd
my:menu selected=$$args{cmd}
   selba href=__URLCAPTION__/a/bbr/sel
  norma href=__URLCAPTION__/abr/norm
/my:menu
/td/tr/table

Did you know that in the body of an XMLSubs, you can do things
like %= $Object-URL % instead of the __URL__.  I begin to
see how it would be nice to offer a set of standard XMLSubs
that can do such things as __TOKEN__ post processing as standard.
I have thought about ports a subset of the standard JSP taglibs
for similar effect so we can have a nice default tag library
to work with too, but have some namespace issues to work though first.

One thing to note that is NOT mentioned on the ASP site-- apparently the
parsing algorithm doesn't know how to handle values that are NOT enclosed
in quotes. Html does not require quotes as long as the value contains no
spaces and only alphanumeric characters. You can't do that here. The other
thing to point out is that any perl variables (eg. $myvar) are NOT escaped
in the usual apache::asp way, (%=$myvar%) but instead are just simply
passed between the quotes. Personally I think this is an inconsistancy, and

In Apache::ASP v3.0 (  2.9xx betas ), there will be the default
syntax of my:sub arg1=%= $var % / instead of the my:sub arg1=$var /
today.  To retain backwared compatibility, there will be an XMLSubsPerlArgs
config that can be set to activate the old method for backwards compatibility.

Other big things will happen in 3.0 like UseStrict becoming default,
which is why 3.0 will be the release for them.  I have already code forked
off the 2.xx branch internally from 3.0 so I can keep doing fixes there
separate from the bigger changes in 3.0.

Thanks for sharing that interesting code sample.

Regards,

Josh


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