in reply to Re: Perl Module Object - Return fail/success with a fault string
in thread Perl Module Object - Return fail/success with a fault string

ok, so bless the hash and then return it, got it. How would I structure it though so that perl sees the exit code within the hash?
  • Comment on Re^2: Perl Module Object - Return fail/success with a fault string

Replies are listed 'Best First'.
Re^3: Perl Module Object - Return fail/success with a fault string
by Corion (Patriarch) on Jan 03, 2012 at 17:08 UTC

    What do you mean by that? Do you ask how to set a key in your hash?

    I think it would help me if you show what you got and show what you want.

      I checked it into a google code SVN repo, so here ya go.

      (Again, I still kinda consider myself a perl noob, atleast as far as creating perl modules goes and using OOP in perl, so don't hate! lol)

      http://big-ip-f5-api.googlecode.com/svn/trunk/

      Basically, if you look in the sample (which some of it works, some doesn't, I doubt you have an F5 laying around to test it on though), the code is as below

      my $connection = BigIP::F5->new($settings); die ("Unable to connect to " . $settings{'server'} . "\nIt said: " . $ +connection->fault) if (!$connection);

      I basically need the logic behind that to work, Yes I could make my module just die or croak, but id rather give the user the ability to end it in their own way if it throws a fail code

        Please don't post (links to) offsite code. I prefer that you take the time to reduce your code (and problem) to a small, self-contained example.

        That said, your example API can be made to work by using overload to return a false value on which you still can call methods. I'm not sure whether that's the best API though. I would (also for testing purposes) split up the call to new and the call to connect, and have the call to connect just return a false value:

        my $conn = Net::Big5->new(...); $conn->connect or die $conn->error;

        That way you can make the call to connect fatal (via die) if it is in void context.

Re^3: Perl Module Object - Return fail/success with a fault string
by ~~David~~ (Hermit) on Jan 03, 2012 at 17:08 UTC
    I would recommend not returning an error code or value. If you don't get the data you need, a good option is to carp/warn and return undef, or die/croak ( depending on whatever is appropriate ).