[26745] in Perl-Users-Digest
Perl-Users Digest, Issue: 8829 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 5 09:05:17 2006
Date: Thu, 5 Jan 2006 06:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 5 Jan 2006 Volume: 10 Number: 8829
Today's topics:
Re: How to create a coderef from an object-method? <samwyse@gmail.com>
Re: How to create a coderef from an object-method? (Bruno Boettcher)
Re: How to create a coderef from an object-method? <phaylon@dunkelheit.at>
Re: why is perl::ssh so slow ? <samwyse@gmail.com>
Re: why is perl::ssh so slow ? <no@email.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 05 Jan 2006 11:41:37 GMT
From: Samwyse <samwyse@gmail.com>
Subject: Re: How to create a coderef from an object-method?
Message-Id: <RB7vf.62935$tV6.36191@newssvr27.news.prodigy.net>
Bruno Boettcher wrote:
> ok, seems i haven't given enough code...
>
> to complete:
>
> Leve.pm:
> package Leve;
> our(%commands);
>
> sub new
> {
> my ($class) = @_;
> my $this = {
> "commands" => \%commands,
> #lots of other class vars#
> };
>
> bless ($this, $class);
> return $this;
> }# sub new
>
> sub print { ... ; }
> $commands{"print"} = "print";
$commands{"print"} = \&print;
> sub leve_list { ... ; }
> $commands{"list"} = "leve_list";
$commands{"list"} = \&leve_list;
> sub leve_clear { ... ;}
> $commands{"clear"} = "leve_clear";
$commands{"clear"} = \&leve_clear;
> etc...
Or you can do all the work at compile time via anonymous subroutines.
Note that => will magically quote the word in front of it, so you don't
need to type them all yourself.
package Leve;
use strict;
sub new {
my $class = shift;
my $this = {
commands => {
print => sub { ... ; },
leve_list => sub { ... ; },
leve_clear => sub { ... ; },
},
};
bless $this, $class;
return $this;
}
> then in xchat2Handler:
> $this->{"leve"} = new Leve();
> $commands = $this->{"leve"}->{"commands"};
>
>>foreach my $cmd (keys(%$commands))
>>{
>> my $funcref = eval("sub { ".$this->{"leve"}."->".$commands->{$cmd}."(@_);}");
my $funcref = $this->{"leve"}->{"commands"}->{$cmd};
>
> #eg for list:
> #my $funcref = eval("sub { ".$this->{"leve"}."->leve_list(@_);}");
> #resulting in a reference to the method: Leve::leve_list($this,@_);
>
>> Xchat::hook_command("l".$cmd, $funcref);
>> Xchat::print("added command handler l".$cmd." calling back on $funcref");
>>}#foreach my $cmd (keys(%$commands))
>
> so i don't think i can access the method coderefs as if they were hash
> values....
Sure you can, if you do it right. Did you try using Data::Dumper, as I
suggested? It will go a long way towards helping debug complex data
structures.
------------------------------
Date: 05 Jan 2006 13:04:36 GMT
From: bboett@bboett.dyndns.org (Bruno Boettcher)
Subject: Re: How to create a coderef from an object-method?
Message-Id: <43bd1964$0$23973$626a14ce@news.free.fr>
In article <RB7vf.62935$tV6.36191@newssvr27.news.prodigy.net>,
Samwyse <samwyse@gmail.com> wrote:
>Bruno Boettcher wrote:
> $commands{"print"} = \&print;
hmmm indeed...
>Or you can do all the work at compile time via anonymous subroutines.
>Note that => will magically quote the word in front of it, so you don't
>need to type them all yourself.
yep but that would rendre the code not really readable, and would
confuse ctags...
>Sure you can, if you do it right. Did you try using Data::Dumper, as I
>suggested? It will go a long way towards helping debug complex data
>structures.
i always use Data::Dumper :D
--
ciao bboett
==============================================================
bboett@adlp.org
http://inforezo.u-strasbg.fr/~bboett
------------------------------
Date: 05 Jan 2006 13:04:36 GMT
From: Robert Sedlacek <phaylon@dunkelheit.at>
Subject: Re: How to create a coderef from an object-method?
Message-Id: <43bd1964$0$26915$9b4e6d93@newsread4.arcor-online.net>
Bruno Boettcher <bboett@bboett.dyndns.org> wrote
> now i have created an object with several methods, and i have a table
> with the commands to add to the client, and now i am trying to find the
> syntax to do this....
Man, I *really* need to integrate perltidy into tin. Anyway, assuming
this:
my $leve = $this->{ leve }; # the object
my $cmd = $this->{ cmd }; # the method?
my @args = qw/ foo bar /; # arguments, I don't know where they are
# coming from in your code
How about this solution:
my $coderef = sub { $leve->$cmd( @args ) };
? That's untested code, tho, but how I would go for it.
--
The eternal mistake of mankind is to set up an attainable ideal.
-- Aleister Crowley
------------------------------
Date: Thu, 05 Jan 2006 11:52:42 GMT
From: Samwyse <samwyse@gmail.com>
Subject: Re: why is perl::ssh so slow ?
Message-Id: <eM7vf.62938$tV6.22322@newssvr27.news.prodigy.net>
What is this 'perl::ssh' of which you speak? I've never heard of it,
and CPAN doesn't seem to know of it, either.
------------------------------
Date: Thu, 05 Jan 2006 11:56:36 +0000
From: Brian Wakem <no@email.com>
Subject: Re: why is perl::ssh so slow ?
Message-Id: <424frlF1h4umtU1@individual.net>
Reinhard Glauber wrote:
> ok, here ist the debug-output .. if it helps ;-)
>
> nobody: Reading configuration data /home/Explorer/.ssh/config
> nobody: Reading configuration data /etc/ssh_config
> nobody: Connecting to 192.168.3.235, port 22.
> nobody: Remote protocol version 2.0, remote software version OpenSSH_3.8.1p1
> nobody: Net::SSH::Perl Version 1.29, protocol version 2.0.
> nobody: No compat match: OpenSSH_3.8.1p1.
> nobody: Connection established.
> nobody: Sent key-exchange init (KEXINIT), wait response.
> nobody: Algorithms, c->s: 3des-cbc hmac-sha1 none
> nobody: Algorithms, s->c: 3des-cbc hmac-sha1 none
> nobody: Entering Diffie-Hellman Group 1 key exchange.
> nobody: Sent DH public key, waiting for reply.
> nobody: Received host key, type 'ssh-dss'.
> nobody: Host '192.168.3.235' is known and matches the host key.
> nobody: Computing shared secret key.
> nobody: Verifying server signature.
> nobody: Waiting for NEWKEYS message.
> nobody: Enabling incoming encryption/MAC/compression.
> nobody: Send NEWKEYS, enable outgoing encryption/MAC/compression.
> nobody: Sending request for user-authentication service.
> nobody: Service accepted: ssh-userauth.
> nobody: Trying empty user-authentication request.
This could be the problem. You will get a ~3 seconds delay after a
failed login attempt on most unix/linux systems.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8829
***************************************