Skip Menu |

This queue is for tickets about the JavaScript CPAN distribution.

Report information
The Basics
Id: 41737
Status: new
Priority: 0/
Queue: JavaScript

People
Owner: Nobody in particular
Requestors: wolf.arthur [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: IRC discution about inclusion of classes ( JavaScript.pm )
Date: Tue, 16 Dec 2008 01:20:54 +0100
To: bug-JavaScript [...] rt.cpan.org
From: "ARTHUR WOLF" <wolf.arthur [...] gmail.com>
Hi. <arthur> is there a convenient way to get lists of all methods and properties of a class ? <arthur> ( like I want an array of methods and an array of properties for the WWW::Mechanize class ) ? <claes> perl has no classes <arthur> yeah, module <arthur> ( it's to feed the JavaScript module so i confused ) <claes> artur: JavaScript.pm? <arthur> claes: yes <claes> artur: it's on my todo list for it <arthur> i wah to do stuff like var mech = new WWW::Mechanize;mech.get(url);print mech.content and so <claes> no <arthur> but bind_class requires I feed all methods and properties and stuff <claes> more like, $cx->bind_class("WWW::Mechanize") <claes> and it'll discover it for you <arthur> claes: seriously ? <claes> but as I said.. time and $$$ doesn't always go hand in hand <arthur> claes: Didn't see it descovers it for me in the doc, I try that <claes> arthur: it doesn't, but it's on my list of things to fix (as I am the author of JavaScript.pm) <claes> hex: well.. for my sky will always be arthur with an h <arthur> claes: how much do you need ? <claes> time or money? <arthur> well, I don't have time :) <claes> arthur: put in a ticket in RT about it and I'll see if I can find time during the holidays (free of charge) <arthur> claes: can you write me a few lines in a mail about how you would do it so i can try doing it myself ? <arthur> ( i'll put a ticket tonight anyway ) <claes> arthur: I'd walk the target package stash or use something like Devel::Symbol <claes> but there should be more magic involved if the target class is b^W^Woozeified <claes> mooseified <arthur> okay, too complicated for me, just the ticket <arthur> thanks a lot <claes> err.. Devel::Symdump is the module I ment ofcourse <claes> arthur: however stuff like content in WWW::Mechanize will be an method in JavaScript since there's no way to check if it's a "property" or regular method unless you use something like moose <arthur> claes: that would be fine <claes> arthur: but for now I think something in the lines of $cx->bind_class(methods => Devel::Symdump->functions("WWW::Mechanize")) would do the trick <arthur> claes: I try that <claes> er.. [Devel::Symdump->functions("WWW::Mechanize")] since "methods" can take a array ref <claes> but it's just a guess.. now I'm off to sleep Okay so I tryed it. Here is my script : #!/usr/bin/perl -w use strict; use JavaScript; use Slurp; use WWW::Mechanize; require Devel::Symdump; my @packs = qw(WWW::Mechanize); my $obj = Devel::Symdump->rnew(@packs); my $script; if ( shift @ARGV eq "-e" ) { $script = shift @ARGV } else { $script = slurp $ARGV[0] } my $rt = JavaScript::Runtime->new(); my $js = $rt->create_context(); $js->bind_class( name => 'Mechanize', constructor => sub { WWW::Mechanize->new(); }, methods => [$obj->functions], package => 'WWW::Mechanize' ); $js->bind_function(say => sub { print @_, "\n"; } ); print "JSError : " , $@, "\n" unless ( $js->eval($script) ); Here is how I call it : arthur@aquarelle:~/dev/svn/js$ perl js.pl -e 'm = new Mechanize();say(m);m.get();' WWW::Mechanize=HASH(0x8fc1ad8) JSError : *m.get is not a function at main line 29 in 1* I don't understand why it doesn't work. Took a look at the code, but I don't understand this part : my ($pkg, $method) = $inspect =~ /^(?:(.*)::)?(.*)$/; $pkg = caller(1) if !defined $pkg || $pkg eq q{}; $pkg = caller(2) if $pkg eq 'JavaScript::Context'; So I'm stuck :) Anyway, this is a ticket to nicely request that the module does what I want by itself, like : $js->bind_class( name => 'Mechanize', package => 'WWW::Mechanize' ); #And thats it ! Thanks a lot ! Have a good week ! -- Courage et Bonne humeur. jabber:wolf.arthur@gmail.com/GSM:0032495318245