logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



WebDyne (Yet Another Perl Web FrameWork) for Apache on Win32

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2581
Location: Hilversum, NL, EU

PostPosted: Fri 21 Jul '06 14:39    Post subject: WebDyne (Yet Another Perl Web FrameWork) for Apache on Win32 Reply with quote

Received the following mail from Andrew.
His website is at http://webdyne.org/

Andrew Speer wrote:
I have released a Perl based web framework for Apache called WebDyne. In its
most basic form WebDyne supports the ability to embed Perl code into HTML
documents, e.g.,

<p>Hello World, the time is <perl> scalar localtime </perl></p>

Of course mixing code and content is not always good, so the Perl code can be
called from an external package also, e.g.,

<p>Hello World, the time is <perl method="MyModule::gettime"/></p>

Beyond the basics WebDyne supports selective rendering of HTML, templating,
caching of dynamic content and other advanced features.

Up until now WebDyne ran only on Linux, however the latest release runs on
Apache 2.0, or Apache 2.2, on Windows.

A Windows setup executable is available and the software is released under the
GPL.

Hope this is of interest to you or your readers who use Perl with Apache.

Andrew Speer
Back to top
ali_fareed



Joined: 04 Jul 2006
Posts: 61
Location: Bahrain

PostPosted: Fri 21 Jul '06 18:58    Post subject: Reply with quote

I'm a bit confused can't you do that with mod_perl?
Back to top
aspeer



Joined: 23 Jul 2006
Posts: 5

PostPosted: Sun 23 Jul '06 18:22    Post subject: Reply with quote

OK, stand back - here is more than you wanted to know about WebDyne ..

WebDyne is written in Perl and is a mod_perl handler itself. WebDyne lets you embed perl directly into a HTML page, which (as far as I know) mod_perl does not let you do - directly, anyway.

In some ways it is similar to PHP - at least in the sense that you write a .php page, which can contain HTML and PHP code; with WebDyne you write a .psp page, which can contain HTML and Perl code.

There a plenty of examples on the web site, http://webdyne.org/. Here is another one which might make a bit more sense .. hopefully ..

Install WebDyne. Create a file call "hello.psp" in your htdocs directory:

<start_html>
<perl method="hello">
<p>
Hello World ${time}
</perl>
<end_html>
__PERL__
sub hello {
my $self=shift();
my $time=scalar localtime;
# will render the block between the <perl>..</perl> tags 3 times
for (1..3) { print $self->render( time=>$time) }
}

Then open up the page in your browser (e.g. http://localhost/hello.psp) - the result is a page with "Hello World <time>" rendered 3 times.

The <start_html> and <end_html> and just syntatic shortcuts - you can still use <html><head> .. etc, but either way the *output* from Apache is legal HTML.

The idea was to get rid of scripts like this:

#!/bin/perl
use CGI;
my $cgi=CGI->new();
print $cgi->start_html, "Hello World", scalar localtime, $cgi->end_html

WebDyne lets you keep the code and content separate and (to me, but I am biased) is a clearer solution than the type of script above.

It starts getting even clearer when branching is required. In scripts you need to mix up HTML <<HERE type docs with if..elsif.. etc statements. It all starts to get a jumbled mess. In WebDyne you define HTML blocks in the page, e.g:

<block name="error">
Sorry, an error occurred, no such user ${user}
</block>

<block name="ok">
No problems, pleased to meet you ${user}
</block>

Then in the Perl code just choose which (if any) block should be rendered:

if (something) {
$self->render_block( 'error', user=>$user)
}
else {
$self->render_block('ok', user=>$user)
}

WebDyne is actually a suite of modules. It can cache dynamic pages to reduce load on the server, wrap pages in templates, and do other reasonably sophisticated tasks.

I have tried to make it as fast as possible - pages are compiled so that it is not constantly re-parsing .psp files looking for executable code. On my quite slow box the "hello.psp" page will render at over 250 pages/sec using ApacheBench.

I accept there are other ways on mixing Perl and HTML (e.g HTML::Mason, Embperl), and am not claiming mine is "the best" - like a lot of software it was written to scratch my own itch, but I hope it may be useful to others also ..

Feedback is welcome.

Regards,

Andrew Speer
Back to top
ali_fareed



Joined: 04 Jul 2006
Posts: 61
Location: Bahrain

PostPosted: Sun 23 Jul '06 22:17    Post subject: Reply with quote

wow thats really nice just like php i'm going to give it a try
Back to top
ali_fareed



Joined: 04 Jul 2006
Posts: 61
Location: Bahrain

PostPosted: Sun 23 Jul '06 22:21    Post subject: Reply with quote

do you have a binary windows package instead of an installer?
Back to top
aspeer



Joined: 23 Jul 2006
Posts: 5

PostPosted: Mon 24 Jul '06 4:48    Post subject: Reply with quote

Sorry - The installer is written with NSIS, which only produces an "setup.exe" type file, not an MSI.

I do not have access to tools for generating an MSI, and even if I did I am probably not really keen to re-write the installer from scratch again !

I know that an MSI package is more "modern", but is there any reason why the exe is not suitable for you ?

WebDyne for Linux is relatively mature, but this is my first attempt at an installer for Windows - if the setup file does not work please let me know and I will follow it up ..

Andrew
Back to top
maniac



Joined: 29 Mar 2006
Posts: 31
Location: Ukraine

PostPosted: Mon 24 Jul '06 6:54    Post subject: Reply with quote

the way works webdyne is like php3. .
today almost all mature php programmers write code that not depends on presentation. In simplest form - using some template engine.
And now webdyne

IMHO, perl is ideal for day-to-day system scripts. or small daemons. or for processing many bytes of text. but not for web applications.
PHP (I'm using it for three years and I hate this language, really) designed specially for web. So it fits better.

I like perl. I use it. but not for web.

However, I think webdyne will find it's small niche. Every idea have it's followers.
It can be very useful for beginner perl programmers.
Back to top
aspeer



Joined: 23 Jul 2006
Posts: 5

PostPosted: Mon 24 Jul '06 8:11    Post subject: Reply with quote

I am not trying to convert PHP programmers back to Perl - all I am doing is offering "Yet Another Way To Do It" for Perl people. Actually all I was doing was writing a Web app in Perl and was not happy with the tools out there, so I wrote my own. Hubris - another sign of using Perl too long !

There is no doubt that Perl is a dying language for Web applications - PHP surpassed Perl a long time ago, and upstarts like Ruby on Rails and Python are probably more popular than Perl also.

Perl is like the grandfather or Web app languages - sits around a lot saying "back in my day ...". WebDyne is Perl shaking its fist and saying "get off my lawn", damn upstart kids !

If nothing else it lowers the barrier of entry - installing WebDyne and cranking out some PSP pages is a lot easier for a beginner than writing a mod_perl handler.

Anyway, although I do not want to go point for point with people (hey, if you like/know something, stick with it) however I will just clarify a couple of things:

The examples are very simplistic - most do mix code and content in an effort to show how aspects of the system work. For more mature projects code and content can (indeed should) be separated.

PSP pages can call Perl routines contained in a central package, with no need to have any Perl code in the HTML page itself (other than the function call) e.g.:

<p>
Echo the time is <perl method="Project::Example::time"/>
<p>
Echo the date is <perl method="Project::Example::date"/>

Where Project::Example is completely separate package. All code for a project can be contained in the package so functions etc can be shared across multiple pages.

The perl code in the package does not (and should not in good practice) contain any HTML, and the HTML should not contain any Perl code. In the package instead of code like this (bad):

if ($error) {
print "<br> sorry that is <strong> wrong !</strong><br>"
}

You can have code like this (good):

if ($error) {
print $self->render_block('error');
}

And in the PSP page a section:

<block name="error">
<br>sorry that is <strong> wrong !<strong><br>
</block>

Localisation/translation just got a bit easier than editing language strings within Perl code.

And to carry on the theme (if anyone is still reading) - WebDyne is a suite of modules. One of the modules is WebDyne::Template, which lets you wrap any HTML page in a template - the simplest example would be a menu type structure with navigation etc.

In fact the WebDyne site (as crappy as the design is - I am no great shakes at graphic design/colour choice) is an example of using templates. Each page can standalone (i.e. it has a <html>..<head>..<body> section, but when rendered with WebDyne::Template it is wrapped in the navigation menu, and is linked with a css file etc.

Have a look at the WebDyne::Template section in the documentation for more information and an example.

I do not know PHP that well, but I think that WebDyne can do some stuff that is not that easy in PHP, such as caching of dyamic contect. The simplest example I can think of: If you have a page that runs an intensive database query it is very easy to tell WebDyne - "cache the output of the page and serve it up from now on. Only generate a new page if the cached one is 10 seconds old".

Try http://webdyne.org/documentation/example/cache1.psp. Click reresh a few times - the time will only be updated once every 10 seconds.

I don't want to start a holy war - maybe the above is just as easy in PHP also.

Anyway - probably more than you wanted to know, but may give a bit more insight into the framework ..

Andrew
Back to top
maniac



Joined: 29 Mar 2006
Posts: 31
Location: Ukraine

PostPosted: Mon 24 Jul '06 11:11    Post subject: Reply with quote

php got it own flaws in caching, true.
the best approach in caching I've ever seen is Smarty.

"Yet Another Way To Do It" - You got me right (:
Nobody lose if we have yet another framework.
Quote:
…I will march up and down the High Street blowing a trumpet and proclaiming at the top of my voice, "NO NEED TO REINVENT THE WHEEL!" on the day that someone actually produces a ROUND WHEEL.

© Stephen Bint
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2581
Location: Hilversum, NL, EU

PostPosted: Mon 24 Jul '06 11:41    Post subject: Reply with quote

ali_fareed wrote:
do you have a binary windows package instead of an installer?

I think ali_fareed meant not a .msi, but a binary package, so not an installer. Just the files we need and instructions to set directives.

I prefer also a binary. I do not like installers, this because I do not know what it installs and changes. I like to have control by myself.

Btw. The installer works not here, it asks for Activestate Perl. I have installed Perl manual and have Perl.exe in my path.

Steffen
Back to top
aspeer



Joined: 23 Jul 2006
Posts: 5

PostPosted: Mon 24 Jul '06 16:02    Post subject: Reply with quote

OK, now I understand - although I don't see why you would have any problems downloading a strange exe from the Internet and running it on your machine - what could possibly go wrong !

I must admit the installer package was designed around the assumption ActiveState Perl would be installed, and that Apache would be installed using the "official" Win32 binaries.

If that is not the case we may have some problems, but let's see how we go ..

I have created a binary package, downloadable from the WebDyne site:

http://webdyne.org/download.psp

1 .. Perl, Apache, mod_perl must already be installed.

2 .. You need to have installed the Visual C++ redistributable package:
http://www.microsoft.com/downloads/details.aspx?familyid=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en

3 .. Unzip the binary zip file onto your machine, preferably to a path without any spaces in the name (it should work with spaces, but we are already tempting fate enough here ..)

4 .. Run the install script: perl.exe c:/<installpath>/webdyne/bin/wdapacheinit

If it does not work please send me the output. You can install WebDyne without running the install script (which is written in Perl - you can read it to see what it does), but it is quite convoluted. Basically the script:

1 .. Finds out where it lives and writes out a file called "Prefix.pm" under the install directory so it can look it up again in the future. It also writes a config file called "perl5lib.pm" to the c:/windows dir containing the install location.

2 .. Creates a cache directory, usually c:/<installpath>/webdyne/cache. The script says "assigning permissions to cache dir", but that is a no-op under Win32.

3 .. Adds a line to the bottom of the httpd.conf file that says "include webdyne.conf"

4 .. Generates webdyne.conf file with the correct path names and stores it in the Apache conf dir.

That is about it. Feedback about successful/failed installs welcome. This is the first Windows release, so please be gentle .. if it does not work please try and tell me as much as possible about your Apache/Perl setup so I can reproduce it.

Andrew Speer
Back to top
ali_fareed



Joined: 04 Jul 2006
Posts: 61
Location: Bahrain

PostPosted: Tue 25 Jul '06 1:46    Post subject: Reply with quote

I just installed webdyne on my windows xp pro sp2 pc it worked great but when I used the berkleydb.pm library it failed because it couldnt load berkleydb.dll I used dependency walker and I found out that libdb44.dll was missing you probably forgot to include it in the package and I would like to ask you can the internal error page be turned off because a page with internal paths and snippets of your code isnt such a great idea in a production server can I use error logging instead.
Back to top
aspeer



Joined: 23 Jul 2006
Posts: 5

PostPosted: Tue 25 Jul '06 4:22    Post subject: Reply with quote

ali_farred, thanks for the feedback. I will add the BerkeleyDB DLL to the package.

I will clean up the error handling in the next few days and make a new release with a few more options (verbose, minimal etc)

In the meantime you can log errors to a file by creating a file called %windir%/constant.pm with the content:

$VAR1={
WebDyne::Constant => {
ERROR => 'c:/path/to/error.log'
} }

(Apologies for the formatting - I don't know how to insert tabs or hard spaces when posting in plain text)

The error message displayed is generated by a WebDyne template, which you can edit if you do not like how much detail is displayed. Search for a file called 'error.psp' in your install directory and modify it to display only the info you want.

Andrew
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1