
Embedding Perl in HTML
I realize that this list may not be the best, or even most =
appropriate, place to ask this question, but I'm just so curious that =
I'm losing sleep over it! =3D;)
What is the best way to embed perl in an HTML file that is _not_ =
located under the cgi-bin directory? I started learning PHP for this =
very reason, but I keep coming back to Perl. I've read some about =
Template Toolkit and others, but what I'm still confused over is if =
these templates _must_ be located in cgi-bin or can you embed code =
anywhere on your site?
If possible, I would like to be able to embed perl, =
placeholders, templates, whatever, anywhere on my site. Perhaps I'm =
working under the wrong impression, but for some reason I'm thinking you =
can't. Hopefully I'm wrong. Any help in pointing me in the right =
direction will be greatly appreciated.
Thanks,
Marc=
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On Fri, Apr 22, 2011 at 10:41 PM, <sono-io [at] fannullone.us> wrote:
> =A0 =A0 =A0 =A0I realize that this list may not be the best, or even most=
appropriate, place to ask this question, but I'm just so curious that I'm =
losing sleep over it! =3D;)
>
> =A0 =A0 =A0 =A0What is the best way to embed perl in an HTML file that is=
_not_ located under the cgi-bin directory? =A0I started learning PHP for t=
his very reason, but I keep coming back to Perl. =A0I've read some about Te=
mplate Toolkit and others, but what I'm still confused over is if these tem=
plates _must_ be located in cgi-bin or can you embed code anywhere on your =
site?
>
> =A0 =A0 =A0 =A0If possible, I would like to be able to embed perl, placeh=
olders, templates, whatever, anywhere on my site. =A0Perhaps I'm working un=
der the wrong impression, but for some reason I'm thinking you can't. =A0Ho=
pefully I'm wrong. =A0Any help in pointing me in the right direction will b=
e greatly appreciated.
>
> Thanks,
> Marc
I hope i am not wrong but you script needs to be in the cgi-bin dir
or where ever ScriptAlias path you have mentioned and Template
Toolkit will achieve your goal
my $tt =3D Template->new( INCLUDE_PATH =3D> "/var/template" ) || die
"template process failed:$!";
%tag =3D ( 'result' =3D> $somevairable );
$tt->process("form.tmpl",\%tag) || die $tt->error();
your /var/template path holds all your teml files and it has to be
chown to apache:apache if the web server is Apache of course .
--
Regards
Agnello D'souza
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
either you're phrasing things wrong or i'm misunderstanding things.
either way, i'll answer as i understand the questions.
On Fri, Apr 22, 2011 at 1:11 PM, <sono-io [at] fannullone.us> wrote:
> =A0 =A0 =A0 =A0I realize that this list may not be the best, or even most=
appropriate, place to ask this question, but I'm just so curious that I'm =
losing sleep over it! =3D;)
>
> =A0 =A0 =A0 =A0What is the best way to embed perl in an HTML file that is=
_not_ located under the cgi-bin directory?
server side includes, iframes, maybe some sort of js parser and then
insert into the dom (forgot the function - dangerous anyways - don't
do it).
=A0I started learning PHP for this very reason, but I keep coming back
to Perl. =A0I've read some about Template Toolkit and others, but what
I'm still confused over is if these templates _must_ be located in
cgi-bin or can you embed code anywhere on your site?
>
you can put your templates wherever you want (at least in catalyst,
you just let it know if it's not in the default location with the
default extension - never used tt on it's own but many do).
> =A0 =A0 =A0 =A0If possible, I would like to be able to embed perl, placeh=
olders, templates, whatever, anywhere on my site. =A0Perhaps I'm working un=
der the wrong impression, but for some reason I'm thinking you can't. =A0Ho=
pefully I'm wrong. =A0Any help in pointing me in the right direction will b=
e greatly appreciated.
i think you're looking for a way to nicely put html into perl than the
other way around. if this is the case, i'd recommend looking at the
dancer documentation (you could just use tt, but why when you've got
nice mvc frameworks to *help* keep your stuff in the right place). if
you have bigger projects or find yourself limited (or just want a
bigger headache) look at catalyst.
outside of what you've asked, if you want real power, look at psgi
(plack in particular).
hth, but not too much :)
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On Fri, Apr 22, 2011 at 1:21 PM, Agnello George
<agnello.dsouza [at] gmail.com> wrote:
> On Fri, Apr 22, 2011 at 10:41 PM, =A0<sono-io [at] fannullone.us> wrote:
>> =A0 =A0 =A0 =A0I realize that this list may not be the best, or even mos=
t appropriate, place to ask this question, but I'm just so curious that I'm=
losing sleep over it! =3D;)
>>
>> =A0 =A0 =A0 =A0What is the best way to embed perl in an HTML file that i=
s _not_ located under the cgi-bin directory? =A0I started learning PHP for =
this very reason, but I keep coming back to Perl. =A0I've read some about T=
emplate Toolkit and others, but what I'm still confused over is if these te=
mplates _must_ be located in cgi-bin or can you embed code anywhere on your=
site?
>>
>> =A0 =A0 =A0 =A0If possible, I would like to be able to embed perl, place=
holders, templates, whatever, anywhere on my site. =A0Perhaps I'm working u=
nder the wrong impression, but for some reason I'm thinking you can't. =A0H=
opefully I'm wrong. =A0Any help in pointing me in the right direction will =
be greatly appreciated.
>>
>> Thanks,
>> Marc
>
> I hope i am =A0not wrong but you script needs to be in the cgi-bin =A0dir
> or where ever ScriptAlias path you have mentioned =A0and Template
> Toolkit will achieve your goal
>
you're correct - i'm 99% sure the tt template files can be wherever
you want it to be though (which you showed in your example) ie, i
don't believe there is any sandbox of any sort in place here. i would
avoid using apache specific key words though.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On Apr 22, 2011, at 10:35 AM, shawn wilson wrote:
> either you're phrasing things wrong or i'm misunderstanding things.
It's probably the former. =3D:\ I'm looking for a way to add =
snippets of perl to my HTML pages, something similar to what PHP offers =
<?php --code goes here-- ?>. At this point, I don't need power, just =
simplicity.
What got me thinking was that I wanted to put some code from my =
shopping cart on my HTML pages (for pricing, etc.) but to make it work, =
the .html files need to be under the cgi-bin directory. Until I go MVC, =
I can't move those files. So I'm looking for a way to add these =
snippets to my .html files.
I realize the Perl wasn't written for this, but I was hoping =
there'd be a template engine that would handle it.
Thanks for the reply,
Marc=
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On Fri, Apr 22, 2011 at 2:10 PM, <sono-io [at] fannullone.us> wrote:
> On Apr 22, 2011, at 10:35 AM, shawn wilson wrote:
>
>> either you're phrasing things wrong or i'm misunderstanding things.
>
> =A0 =A0 =A0 =A0It's probably the former. =3D:\ =A0I'm looking for a way t=
o add snippets of perl to my HTML pages,
^^^^ says server side includes to me.
something similar to what PHP offers <?php =A0--code goes here-- =A0?>.
At this point, I don't need power, just simplicity.
>
^^^^ says template toolkit
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On Apr 22, 2011, at 10:21 AM, Agnello George wrote:
> my $tt =3D Template->new( INCLUDE_PATH =3D> "/var/template" ) || die
> "template process failed:$!";
> $tt->process("form.tmpl",\%tag) || die $tt->error();
It appears that I'd have to explicitly name the template file in =
my script. If that's the case, it's not exactly what I was looking for. =
I may have to rethink my site to be able to do what I want.
Thanks for the reply,
Marc=
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On Apr 22, 2011, at 11:20 AM, shawn wilson wrote:
> ^^^^ says server side includes to me.
> ^^^^ says template toolkit
Thanks, Shawn. I'll give these a try, as well as the others you =
mentioned in your previous email. I hadn't heard of PerlDancer before, =
but it looks interesting. I have to finish reading "Effective Perl =
Programming" first, though.
Marc=
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
From: <sono-io [at] fannullone.us>
I realize that this list may not be the best, or even most appropriate, =
place to ask this question, but I'm just so curious that I'm losing =
sleep over it! =3D;)
What is the best way to embed perl in an HTML file that is _not_ located =
under the cgi-bin directory? I started learning PHP for this very =
reason, but I keep coming back to Perl. I've read some about Template =
Toolkit and others, but what I'm still confused over is if these =
templates _must_ be located in cgi-bin or can you embed code anywhere on =
your site?
If possible, I would like to be able to embed perl, placeholders, =
templates, whatever, anywhere on my site. Perhaps I'm working under the =
wrong impression, but for some reason I'm thinking you can't. Hopefully =
I'm wrong. Any help in pointing me in the right direction will be =
greatly appreciated.
Do you want to create say... a file like "index.pl" that contains =
something like:
<?perl
use DateTime;
print DateTime->now->ymd;
?>
Some HTML code here
<?perl some Perl code here ?>
If the answer is yes, then no, it is not possible to do this in Perl, =
and it is not recommended to do it in PHP either (although this seems to =
appear as beeing the biggest advantage of PHP for the beginners that =
past from HTML to server side programming.)
It is not recommended to do this because it is not recommended to mix =
HTML code and programming code. The recommended way is to use a =
templating engine like Smarty under PHP, or Template-Toolkit under Perl.
There are more templating engines for Perl, like Mason, HTML::Template =
and many others but the most clear and used seems to be =
Template-Toolkit.
As well as for a web designer is recommended to keep the JS code, CSS =
code and HTML code in separate files if possible, for a server-side =
programmer is recommended to keep the programming code separately.
In a Mason template you can embed Perl code directly, but it becomes =
harder to maintain on the long term and it might make the life of the =
web designer harder. You can also embed Perl code in a Template-Toolkit =
template, but it is not recommended to do that for the same reason, =
however Template-Toolkit has its own limited language which is simple =
and clear.
If you'll use a web framework like Catalyst, you don't even need to =
define the object variable that need to render the templates, because =
this is done automaticly, as many other things, so you don't need to be =
afraid to start learning to use a templating engine like =
Template-Toolkit.
Octavian
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On 2011-04-22 19:11, sono-io [at] fannullone.us wrote:
> What is the best way to embed perl in an HTML file that is _not_ located under the cgi-bin directory?
I don't understand why you involve cgi-bin in your question, but maybe
you are looking for PLP: http://search.cpan.org/~shiar/PLP/
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On Fri, Apr 22, 2011 at 2:55 PM, Dr.Ruud <rvtol+usenet [at] isolution.nl> wrote:
> On 2011-04-22 19:11, sono-io [at] fannullone.us wrote:
>
>> What is the best way to embed perl in an HTML file that is _not_ located
>> under the cgi-bin directory?
>
> I don't understand why you involve cgi-bin in your question, but maybe you
> are looking for PLP: http://search.cpan.org/~shiar/PLP/
>
^^ would be cool if it didn't look so ridiculous :)
i didn't really understand why he mentioned cgi either but let it
fall. i guess i shouldn't have sense most people don't realize that
cgi has absolutely nothing to do with running programs on a web server
- it is a 'gateway interface' supported by web servers that allow a
client to send data to the server (using get, post, delete, and insert
iirc). again, cgi has nothing to do with *running* a program, sending
data to the client, rendering a dom, running js - NOTHING! it is just
a *limited* framework for a client to send data to a server.
and, when i say 'limited', i really do mean that. look at socket.io to
start reading on how cgi fails if you want.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
> I don't understand why you involve cgi-bin in your question,
I was trying to be concise, and not take up too much space and =
time on something that may not have been appropriate for this list, but =
apparently I was more vague than concise. =3D:\ Sorry.
I've been working with an older Perl shopping cart script and =
the placeholders it uses are only accessible on pages that are placed =
under the cgi-bin directory, so I took it (probably incorrectly) that =
Perl code would not work outside that directory.
Let me rephrase my question. I want to show pricing and other =
dynamic information from my shopping cart on my static HTML pages =
throughout my site. I know I can do it with PHP, but being that the =
cart is written in Perl - and I really want to stick with Perl - I =
thought there might be a way to show this info from my store with some =
kind of a Perl templating system.
Being that the info is in a MySQL db, I don't need to access the =
cart, but I'd like to find a way to use Perl to insert this info on =
those pages.
Again, sorry for the confusion.
Marc=
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On 04/22/2011 10:11 AM, sono-io [at] fannullone.us wrote:
> I realize that this list may not be the best, or even most
appropriate, place to ask this question, but I'm just so curious that
I'm losing sleep over it! =;)
> What is the best way to embed perl in an HTML file that is _not_
located under the cgi-bin directory? I started learning PHP for this
very reason, but I keep coming back to Perl. I've read some about
Template Toolkit and others, but what I'm still confused over is if
these templates _must_ be located in cgi-bin or can you embed code
anywhere on your site?
> If possible, I would like to be able to embed perl, placeholders,
templates, whatever, anywhere on my site. Perhaps I'm working under the
wrong impression, but for some reason I'm thinking you can't. Hopefully
I'm wrong. Any help in pointing me in the right direction will be
greatly appreciated.
I've had similar experiences with PHP.
Perl is extremely flexible. Depending upon your particulars, you can
put Perl scripts under cgi-bin/, you can put Perl scripts under
public_html/, you can invoke Perl scripts from within web page source
files, you can put Perl code inside web page source files, you can put a
Perl interpreter and handlers inside your web server, you can write a
Perl web server, and other permutations that I've forgotten or haven't
tried yet. The upside of TIMTOWTDI [1] is that there are lots of
choices. The downside is that finding the right set of choices for a
particular person and project is a non-trivial undertaking.
This article has good background information and got me thinking in the
right direction. Unfortunately, it is getting dated and doesn't cover
Catalyst, "Modern Perl", etc.:
http://perl.apache.org/docs/tutorials/tmpl/comparison/compar ison.html
Over the years, I've studied, attempted, and/or applied many Perl web
technologies with varying degrees of success. I'm currently attempting
to build a Perl CMS using LWP to replace Drupal 6 on my personal/
community web site [2]. My fall-back choice is Mason (version 1.x),
which might work for you. Mason is mature, widely used, well
understood, and there's good documentation available; notably:
http://www.masonhq.com/?OreillyBook
HTH,
David
References:
[1] http://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_ do_it
[2] http://holgerdanske.com/
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On Fri, Apr 22, 2011 at 11:15 PM, David Christensen
<dpchrist [at] holgerdanske.com> wrote:
> On 04/22/2011 10:11 AM, sono-io [at] fannullone.us wrote:
>
>> =A0 =A0 =A0 I realize that this list may not be the best, or even most
>> appropriate, place to ask this question, but I'm just so curious that I'=
m
>> losing sleep over it! =3D;)
>> =A0 =A0 =A0 What is the best way to embed perl in an HTML file that is _=
not_
>> located under the cgi-bin directory? =A0I started learning PHP for this =
very
>> reason, but I keep coming back to Perl. =A0I've read some about Template
>> Toolkit and others, but what I'm still confused over is if these templat=
es
>> _must_ be located in cgi-bin or can you embed code anywhere on your site=
?
>> =A0 =A0 =A0 If possible, I would like to be able to embed perl, placehol=
ders,
>> templates, whatever, anywhere on my site. =A0Perhaps I'm working under t=
he
>> wrong impression, but for some reason I'm thinking you can't. =A0Hopeful=
ly I'm
>> wrong. =A0Any help in pointing me in the right direction will be greatly
>> appreciated.
>
> I've had similar experiences with PHP.
>
>
> Perl is extremely flexible. =A0Depending upon your particulars, you can p=
ut
> Perl scripts under cgi-bin/, you can put Perl scripts under public_html/,
> you can invoke Perl scripts from within web page source files, you can pu=
t
> Perl code inside web page source files, you can put a Perl interpreter an=
d
> handlers inside your web server, you can write a Perl web server, and oth=
er
> permutations that I've forgotten or haven't tried yet. =A0The upside of
> TIMTOWTDI [1] is that there are lots of choices. =A0The downside is that
> finding the right set of choices for a particular person and project is a
> non-trivial undertaking.
>
per "you can put a Perl interpreter and handlers inside your web
server" you might look for a modperl script to handle what you want.
something that puts your perl in every web page. this had good ideas:
http://modperlbook.org/html/4-2-7-Stacked-Handlers.html
you might also check out this book - this chapter in particular might
be helpful:
http://docstore.mik.ua/orelly/weblinux2/modperl/appb_15.htm
this was so well written, i couldn't help sharing:
https://perl.apache.org/docs/2.0/user/handlers/filters.html
you can also do this (pretty easy) with psgi, check this out for ideas
(it's a bit outdated for psgi but i think i'm bookmarking this one
anyway :) ):
http://perliscope.blogspot.com/2009/11/psgi-and-plack-future -of-web.html
notice how i prefer the sledgehammer approach? i like handling as much
as possible before the app ever sees *anything*. this is just
preference. reread what David said. it's worth noting.
note: i think we're out of the realm of 'beginner' here so i'm just
passing ideas. if you want to try and tackle one, i think it might be
very worth while. however, if you find yourself stuck either ask or
don't worry about it.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On 04/22/2011 05:33 PM, sono-io [at] fannullone.us wrote:
> I've been working with an older Perl shopping cart script and the
placeholders it uses are only accessible on pages that are placed under
the cgi-bin directory,
Is there documentation for this script on the WWW? If so, what is the
URL? If not, please explain "placeholders" and how the script works.
I assume you have the source code for the script? If so, perhaps you
can modify it to work with pages in places other than the cgi-bin directory?
> Let me rephrase my question. I want to show pricing and other
dynamic information from my shopping cart on my static HTML pages
throughout my site. I know I can do it with PHP, but being that the
cart is written in Perl - and I really want to stick with Perl - I
thought there might be a way to show this info from my store with some
kind of a Perl templating system.
> Being that the info is in a MySQL db, I don't need to access the
cart, but I'd like to find a way to use Perl to insert this info on
those pages.
I'd say use the best tool for the job, regardless of what language the
shopping cart script is written in. That said, my brain scrambles when
I try to use two similar languages at the same time (e.g. Perl and PHP).
I do better using one language, and I prefer Perl.
If you know the schema for the shopping cart database, Perl can read the
data via the DBI and DBD::mysql modules. Putting the data into static
HTML pages depends upon your web server. I use Apache 2.2. Assuming an
unpriviledged name-based virtual hosting account, I'd try an Apache
rewrite rule in .htaccess that sends the request to a CGI script, that
in turn reads the page, reads the data, feeds them through a template
engine (say, HTML::Template), and sends the result.
I don't remember enough about Mason to suggest how to integrate Mason
with your existing script and static pages. I'd ask the question on the
mason-users mailing list:
https://lists.sourceforge.net/lists/listinfo/mason-users
E-commerce is a known killer app. Perhaps you should migrate your site
to an open-source e-commerce platform and configure/ brand it to meet
your needs? For example, Interchange:
http://www.icdevgroup.org/i/dev
HTH,
David
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Embedding Perl in HTML
On 04/22/2011 11:22 AM, sono-io [at] fannullone.us wrote:
> On Apr 22, 2011, at 10:21 AM, Agnello George wrote:
>> my $tt = Template->new( INCLUDE_PATH => "/var/template" ) || die
>> "template process failed:$!";
>> $tt->process("form.tmpl",\%tag) || die $tt->error();
>
> It appears that I'd have to explicitly name the template file in my script. If that's the case, it's not exactly what I was looking for. I may have to rethink my site to be able to do what I want.
On Apache, you can make the template directory and file locations
variables via the PATH_TRANSLATED environment variable (or corresponding
CGI::path_translated() method).
HTH,
David
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/