cmv has asked for the wisdom of the Perl Monks concerning the following question:

Objectwize Monks-

I'm trying to learn the musty innards of POE::Component::RemoteTail, and have successfully run a modified version example program listed in the documentation.

use strict; use warnings; use Data::Dumper; use POE; # This should be added to the docs... use POE::Component::RemoteTail; my ( $host, $path, $user ) = (qw(myhost.domain.com /home/mylogin/.profile mylogin)); my $alias = 'Remote_Tail'; # spawn component my $tailer = POE::Component::RemoteTail->spawn( alias=>$alias ); # create job my $job = $tailer->job( host=>$host, path=>$path, user=>$user, ); # prepare the postback subroutine at main POE session POE::Session->create( inline_states=>{ _start=>sub { my ( $kernel, $session ) = @_[ KERNEL, SESSION ]; # create postback my $postback = $session->postback("MyPostback"); # post to execute $kernel->post( $alias, "start_tail"=>{ job=>$job, postback=>$postback } ); }, # return to here MyPostback=>sub { my ( $kernel, $session, $data ) = @_[ KERNEL, SESSION, ARG1 ]; print STDERR "DATA DUMP:\n", Dumper($data), "\n"; }, }, ); POE::Kernel->run();
Now, I'm trying to follow the docs to run the (slightly modified) example script (see readmore below) to use the NetSSHPerl custom engine with this module, that is described in POE::Component::RemoteTail::Engine::NetSSHPerl, and I keep getting the error:

Can't locate object method "new" via package "POE::Component::RemoteTail::CustomEngine::NetSSHPerl" at lib/POE/Component/Remotetail.pm line 102.

I'm suspecting that the object stuff isn't setup correctly in the RemoteTail/CustomEngine/NetSSHPerl.pm file, but I don't know enough to fix it.

use strict; use warnings; use POE; use POE::Component::Remotetail; my ( $host, $path, $user ) = (qw(myhost.domain.com /home/mylogin/.profile mylogin)); my $tailer = POE::Component::RemoteTail->spawn(); my $job = $tailer->job( host => $host, path => $path, user => $user, process_class => "POE::Component::RemoteTail::CustomEngine::NetS +SHPerl" ); POE::Session->create( inline_states => { _start => sub { my $kernel = $_[KERNEL]; $kernel->post($tailer->session_id(), "start_tail" => {jo +b => $job}); $kernel->delay_add("stop_job", 100); }, stop_job => sub { my $kernel = $_[KERNEL]; $kernel->post($tailer->session_id(), "stop_tail" => {job + => $job}); } } ); POE::Kernel->run();
Any help is very much appreciated!

Thanks

-Craig

Replies are listed 'Best First'.
Re: POE::Component::RemoteTail - Can't locate object method new
by rcaputo (Chaplain) on Feb 24, 2009 at 17:01 UTC

    If you've correctly spelled "POE::Component::RemoteTail::CustomEngine::NetSSHPerl", then it appears you haven't loaded that module. Will POE::Component::RemoteTail automatically use() it for you? I didn't see that mentioned in a quick skim of the docs....

      Rocco-

      Will POE::Component::RemoteTail automatically use() it for you?

      I think so, here's a code excerpt from RemoteTail.pm:

      102 # use custom class 103 if ( my $class = $job->{process_class} ) { 104 $class->require or die(@!); 105 $class->new(); 106 %program = ( Program => sub { $class->process_entry($j +ob) }, ); 107 }
      Also, I added a print statement to the beginning of the NetSSHPerl module, and I saw the print output before the error message came out.

      I'm also confused because I don't understand the meat of the RemoteTail::CustomEngine::NetSSHPerl module:

      use POE::Component::RemoteTail::CustomEngine::NetSSHPerl; use strict; use warnings; use Net::SSH::Perl; print STDERR "In NetSSHPerl...\n"; #Added by cmv sub process_entry { my $self = shift; my $arg = shift; my $host = $arg->{host}; my $path = $arg->{path}; my $user = $arg->{user}; my $password = $arg->{password}; my $cmd = "tail -f $path"; my $ssh = Net::SSH::Perl->new( $host, protocol => "2,1" ); $ssh->login($user); $ssh->register_handler( "stdout", sub { my ( $channel, $buffer ) = @_; my $log = $buffer->bytes; print $log; unless ($log) { exit; } } ); my ( $stdout, $stderr, $exit ) = $ssh->cmd($cmd); } 1;
      Why does it have a use statement pointing to itself?
      Shouldn't it have a module declaration instead?

      I'm confused.

        That does look bizarre. Off the top of my head, I would expect the use statement to be package and perhaps it's missing a use base pragma.

        This module seems to need some love. Maybe the author would be willing to heap some on it if they knew someone was trying to use it?

POE::Component::RemoteTail - Additional Suggested Enhancements
by cmv (Chaplain) on Feb 24, 2009 at 19:02 UTC
    As I'm delving deeper into this module, I'm finding various situations that the module running the standard ssh command, doesn't address too well. I'm planning on provide the author with code modification suggestions.

    -Hangs on exec errors (ssh isn't in path or executable). I think this is due to not closing the POE wheel properly (Rocco?).
    -No warnings or errors are currently being printed out on exec errors.
    -No way to add command line options to the ssh command to be run
    -Needs expanded debug statements.

    Please add to this thread any additional issues you may find, and I'll try to condense it into a group of suggestions for the author.

    Thanks

    -Craig

    Update:
    -The existing Net::SSH::Perl custom engine will only work with SSH protocol 2 as written.

      Hi! My name is Takeshi Miki, author of POE::Component::RemoteTail.

      Thank you for your suggestions.
      I uploaded the version of improved ones to CPAN a moment ago. I was not able to apply all of your suggestion, but lost the clear bug.

      Check it out and enjoy!

      thanks.