On 2/22/2012 9:01 PM, Harvey S. Frey wrote:
> Problem: I want to use an HTML page as an alternative to Windows
> Explorer, so I can annotate, edit and sort files. BUT, Javascript won't
> let me access any local files.
>
> Desired solution: Embedding perl scripts to let me, for example, run an
> editor on a file. I suppose I could do it if I ran a local server, like
> TomCat, but that gets to be too much of a kludge.
>
> Question: Can I use Mason to embed perl scripts in an HTML file, which I
> can run locally, without a server?

Hi Harvey,

It may help to understand the basic processes going on.

When you wish to display a web site, first your browser sends a request 
for the URL of that page to the server.  It receives back, from the 
server, the HTML, usually.  The browser then scans that HTML and figures 
out what else it needs: CSS, images, and so on.  It then requests these 
and renders them.

The browser is just requesting and the server is just sending static 
files.  It is the browser that is actually acting on them; converting a 
.gif image binary into colored pixels, using the HTML and CSS files to 
build the page layout, etc.  In this sense the browser is acting like a 
server, taking raw data and serving up graphical content on your screen 
(or maybe textual content if it is lynx, spoken content if it is a 
screen reader, etc).

On the client side, the dynamic functionality of a web page comes from 
Javascript, which is a language that the browser understands.  The key 
here is that the browser runs the Javascript, not the server.  The 
server is simply sending plain text files with the Javascript source code.

On the server side, the role of Mason is to take raw data, in the form 
of the request URL and various files, and turn that into HTML.  The 
browser has no idea if the HTML it got from the server was originally a 
static file, some programming in PHP, Perl / Mason, or server side Java 
from something like Tomcat; and it doesn't care.  All it needs is the 
HTML file - how that file is produced by the server is not relevant.

In the case of Java, there are two modes: server side and client side. 
Server side runs in an application server, like Tomcat, and client side 
runs in a plug-in on the browser like the Sun Java plug-in.  Javascript 
is similar, except that it is usually compiled into the browser and does 
not need a plug-in.  Interestingly, it is possible for a Javascript 
application on the client to make requests to a Javascript application 
server.  Neither Javascript engine would know it was communication with 
Javascript at the other end, and neither needs to know.

Basically, what you are describing in your question is the ability to 
run Mason the same way you run Javascript - in the browser.  The 
traditional model is that Javascript runs in the browser and Perl / 
Mason runs on the server.  That is the underlying problem.

Your browser is able to request files from the local filesystem, without 
the need for a true server, however, the windows filesystem is not 
normally capable of running applications in this manner.

1) The first solution is to get the browser to run Perl natively.  This 
would likely be as a plug-in, the same way as Java.  There have been 
attempts at this in the past.  Since Perl was not written with this 
application in mind, adapting Perl to have a proper security model is 
challenging.

http://docstore.mik.ua/orelly/perl3/tk/ch22_02.htm

http://www.perlmonks.org/?node_id=514661


2) Without monkeying around with your browser, you could, as Jonathan 
suggested, run a server on your local computer that your browser makes 
requests to.  There are a lot of lightweight servers, plus Apache 
installs and runs nicely as a service, if you do not mind its fairly 
large footprint.


3) It may be possible to use the browser's native file access to do as 
you wish, but you would have to set up a file system driver so that when 
you access a certain directory, it runs a program.  In this case, that 
program would be your Mason handler, that is normally handled by the web 
server (see app.psgi in Jonathan's tutorial).

http://en.wikipedia.org/wiki/Installable_File_System

http://dokan-dev.net/en/

You would need Perl on your system.  Look into Strawberry Perl.  You 
would need to install all the Perl modules that Mason needs and some of 
them have an XS component for speed.  If they provide a Pure Perl 
version, it could work, but would be slower.  Moose is already pretty 
slow and this model is acting like a CGI request so you would not get 
the benefits of something like FastCGI or mod_perl.  A compiler is not 
included on windows by default, but if you can install one, you should 
be able to build the XS modules.


4) In fact, Javascript is an environment agnostic language. 
Historically, for security reasons, in the browser it has been heavily 
sandboxed.  But, with HTML5, you can now access local files with the 
File APIs.

W3C specification for File APIs: http://www.w3.org/TR/file-upload/

Example of how to use it: 
http://www.html5rocks.com/en/tutorials/file/dndfiles/


So, generally, doing what you wish is a lot of work, unless you choose 
option #4, in which case, this is no longer a Mason question.

Cheers.

Paul Wallingford

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to