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

UPDATE: OK, someone shoot me. I stupidly changed the function to put the return value as the croak statement. I need some sleep. Someone please delete this.

Monks, I'm stumped on something that's probably pretty obvious but is escaping me. I'm wondering if I can please get second pair of eyes because this is driving me crazy.

So this works fine:

$cmd = qq(perl -e "print ((stat '$path')[4])"); my $uid = $self->ssh->capture($cmd);

$self->ssh is a Moose attribute containing a Net::OpenSSH object (see below). $uid returns an expected "1000."

However, when I call the same command with my grab wrapper method for the Net::OpenSSH:

$cmd = qq(perl -e "print ((stat '$path')[4])"); my $uid = $self->grab($cmd); { package MyOpenSSH 0.000001; use Carp; use Data::Dumper; use Moose::Role; use Modern::Perl; use Net::OpenSSH; use Params::Validate; has 'ssh' => (is => 'rw', isa => 'Net::OpenSSH', required => 1, lazy + => 0, handles => qr/.*/, ); sub grab { my $self = shift; my $opts = shift; $self->ssh->capture($opts, @_); croak ('ssh command failed') if $self->ssh->error; } }

the $uid is set to '0'. What am I missing?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: Wrapper method not returning same result as calling method directly
by trippledubs (Deacon) on Mar 16, 2017 at 01:48 UTC
    $self->grab, really?

      Who says programming isn't exciting?

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        Don't bite.

        I asked today over on SO one of the most basic questions a C programmer could possibly ask.

        Another "do'h" moment. Take it in stride. Attempts at success show success imho.

        Now, if it were $self->suck;, I'd just stay out of it ;)

Re: Wrapper method not returning same result as calling method directly
by Anonymous Monk on Mar 16, 2017 at 01:42 UTC

    Call to deletion is overly dramatic. The update-note about you finding/fixing the issue yourself is just enough.

      Agreed. We've all have had those "do'h!" moments, wishing we could remove things. OP: Start looking at it from the perspective of something Your Mother and GrandFather taught me a long time ago... Rubber Duck Debugging.

      Things don't get deleted (ie. reaped) here, unless there is very good cause to do so. Believe me... using tactics like boldface and large size fonts don't work; the NodeReaper is blind to such attempts :)

      Chalk it up to experience gained, and take with a grain of salt a piece of my advice: There is no such thing as a stupid question (despite wanting to erase yourself from existence when you 'think' you've fscked up).