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

What you want is certainly possible, but your code in Module::Test is not how you construct objects (or "objects"). Please have a look at bless or one of the object tutorials. If your objects are merely collections of data, just return an unblessed hash reference:

sub new { ... return \%return };

Replies are listed 'Best First'.
Re^2: Perl Module Object - Return fail/success with a fault string
by jhyland87 (Sexton) on Jan 03, 2012 at 16:56 UTC
    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?

      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

      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 ).