Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Re: Creating Advanced Client-Side Applications With Perl

by dragonchild (Archbishop)
on Apr 16, 2004 at 21:34 UTC ( [id://345878]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Creating Advanced Client-Side Applications With Perl
in thread Creating Advanced Client-Side Applications With Perl

I want to create single-user applications to be run on a single PC that you download. The installer would include ActivePerl, should it be necessary. I can't use JavaScript because I want to use DBD::SQLite, plus I don't want to learn a whole new language.

Put it this way - the simple utility apps I want to create and distribute would take between 2-4 days each ... assuming I can use Perl for DBD::SQLite and HTML::Template. The engines for these utilities are very small and easy ... Heck, I've already written most of the engines for two of the utilities in the general course of my work. I don't want to reimplement them, if at all possible, or spend a month learning Tk. But, I don't want to require using a webserver, even one as small as webmin.

As for not needing much to document ... Converting from JScript to PScript is almost impossible for non-trivial cases. Take the following rather simplistic example in JavaScript:

<html> <head> <title>Test</title> <script language="JavaScript"> var button1 = '<input type="button"' + ' name="click1"' + ' value="Button1"' + ' onclick="parent.click1()"' + '>'; var button2 = '<input type="button"' + ' name="click2"' + ' value="Button2"' + ' onclick="parent.click2()"' + '>'; function update () { window.contentFrame.document.open("text/html"); window.contentFrame.document.write( button1 ); window.contentFrame.document.close(); } function click1 () { window.contentFrame.document.open("text/html"); window.contentFrame.document.write( button2 ); window.contentFrame.document.close(); } function click2 () { window.contentFrame.document.open("text/html"); window.contentFrame.document.write( button1 ); window.contentFrame.document.close(); } </script> </head> <frameset onLoad="update()"> <frame src="about:blank" name="contentFrame" noresize> </frameset> </html>

Here's the direct translation (as I understand it) to PerlScript.

<html> <head> <title>Test2</title> <script language="PerlScript"> $button1 = q{ <input type="button" name="click1" value="Button1" onclick="$parent->click1()" language="PerlScript" > }; $button2 = q{ <input type="button" name="click2" value="Button2" onclick="$parent->click2()" language="PerlScript" > }; sub update() { $window->contentFrame->document->open("text/html"); $window->contentFrame->document->write( $button1 ); $window->contentFrame->document->close(); } sub click1 () { $window->contentFrame->document->open("text/html"); $window->contentFrame->document->write( $button2 ); $window->contentFrame->document->close(); } sub click2 () { $window->contentFrame->document->open("text/html"); $window->contentFrame->document->write( $button1 ); $window->contentFrame->document->close(); } </script> </head> <body name="parentFrame" onLoad="update()" language="PerlScript"> <frame src="about:blank" name="contentFrame" noresize> </body> </html>

The JavaScript version works as expected, but the PerlScript one doesn't even run the onLoad handler. What's the difference? What am I missing?

I'm on WinXP Pro, IE 6.0.2x, the latest build of ActivePerl (downloaded within the past week).

Update: Changed to match Erto's statement. It still doesn't work.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Replies are listed 'Best First'.
Re: Re: Re: Re: Creating Advanced Client-Side Applications With Perl
by Jenda (Abbot) on Apr 19, 2004 at 17:51 UTC

    Are you sure it's not called?

    Try to add

    use Win32; Win32::MsgBox("How are you?");
    into the subroutine. It seems to me it does get called (IE 6.0.2800.1106), but the code doesn't do anything.

    I tried to fix it but I can't find the contentFrame. I tried to use

    sub displayObj { my $obj = shift(); Win32::MsgBox("Keys: " . join(', ', map { "$_ => $obj->{$_}" } sor +t keys %$obj )); } ... displayObj( $window); displayObj( $window->{document}); ...
    , but I can't find anything.

    Quite possibly it would be best to use JavaScript for most of the "client-side" stuff and only call some PerlScript subroutines from the JavaScript.:

    <SCRIPT LANGUAGE="PerlScript"> sub DoSelectSite { $window->{document}->{Location} = $window->{document}->Forms( 0 )- +>{SiteSelector}->{Value}; } </SCRIPT> <script language="JavaScript"> function SelectSite () { DoSelectSite(); } </script> <BODY> <P>Select a site to browse.</P> <HR> <FORM> <SELECT NAME="SiteSelector" SIZE = "1" onChange="JavaScript:SelectSite +()"> <OPTION VALUE="">--select one-- <OPTION VALUE="http://www.ncat.edu">North Carolina A and T State Unive +rsity</OPTION> <OPTION VALUE = "http://www.uncg.edu">University of North Carolina at +Greensboro</OPTION> </SELECT> </FORM> </BODY>

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

      The question here, imho, isn't whether or not it's called. (Though, I don't think it is because putting in a $window->alert("It's me!"); doesn't pop up.) It's what mistake(s), if any, did I make in trascribing the JavaScript into PerlScript. PerlScript on the client-side is advertised as being identical to JavaScript, albeit with Perl's power. Where did I go wrong??

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        One of the problems in your code is that this JavaScript

        window.document.formname.fieldname.value = 5;
        needs to be translated to this PerlScript:
        $window->{document}->{formname}->{fieldname}->{value} = 5;
        Notice the curlies! The second problem is that JavaScript looks for objects in more places. Eg. It's OK to write the code above like this:
        document.formname.fieldname.value = 5;
        since JavaScript searches through the properties of the active window object if it doesn't find a variable of that name. OTOH
        $document->{frm2}->{code}->{value} = 5;
        is not valid.

        Likewise if I add <div id="foo" name="this is foo">Ahoj</div> into the page and run alert(foo) in JavaScript I get [object]. If I try to run alert($foo); in PerlScript I get nothing. I bet there is a way to get that object, but I don't know how.

        Jenda
        Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
           -- Rick Osborne

        Edit by castaway: Closed small tag in signature

Re: Re: Re: Re: Creating Advanced Client-Side Applications With Perl
by Errto (Vicar) on Apr 17, 2004 at 23:03 UTC
    I've never tried PerlScript in IE, but what strikes me off the bat is that in your translation you renamed the "update" function but didn't modify the HTML accordingly. So you should change onLoad="update()" to onLoad="parentFrame_onLoad()" and try that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://345878]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found