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

Hello,

I'm writing some code that interacts with a F5 BigIP load balancer using the BigIP::iControl Perl module.

However the .pm file available is very out of date compared to the API now available so I am having to manually update the .pm with the additional functionality I need.

I've used Perl for some time now, but never done anything like this, and I am having some issue with accessing the objects that are being returned to me.

The context of this might be irrelevant, but I wanted to give some background.

I am being given the following object, but I cannot work out how I can access the values inside the second bless:

$VAR1 = bless( [ bless( { 'availability_status' => 'AVAILABILITY_STATU +S_RED', 'status_description' => 'Pool member has bee +n marked down by a monitor', 'enabled_status' => 'ENABLED_STATUS_ENABLED' }, 'LocalLB::ObjectStatus' ), bless( { 'availability_status' => 'AVAILABILITY_STATU +S_RED', 'status_description' => 'Pool member has bee +n marked down by a monitor', 'enabled_status' => 'ENABLED_STATUS_ENABLED' }, 'LocalLB::ObjectStatus' ) ], 'LocalLB::ObjectStatus[]' );

It looks a little odd to me as I was not expecting to have a bless inside another bless object.

Here is the API and Method in question https://devcentral.f5.com/wiki/iControl.LocalLB__Pool__get_member_object_status.ashx

Any help with this would be appreciated, let me know if you would like more information.

Thanks,

Darren

Replies are listed 'Best First'.
Re: Object Access Issue
by tobyink (Canon) on Mar 19, 2014 at 10:08 UTC

    As robby_dobby said, it's not unusual for blessed objects to have other blessed objects as members.

    What is unusual is the package name that the outer object is blessed into: 'LocalLB::ObjectStatus[]'. It's not technically a problem, but quite weird to put square brackets in a package name.

    use 5.010; use strict qw(vars subs); use warnings; *{"Foo[]::hello"} = sub { say "Hello" }; my $obj = bless({}, "Foo[]"); $obj->hello;
    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re: Object Access Issue
by robby_dobby (Hermit) on Mar 19, 2014 at 09:29 UTC
    Hello Darren123,

    No, this is not a "bless inside another bless" as you put it. It's simply an array of LocalLB::ObjectStatus objects. So you iterate over this array and gather values out of items as you access them. Here's a PM post talking about arrays of objects in OOPerl.

Re: Object Access Issue
by Bloodnok (Vicar) on Mar 19, 2014 at 11:21 UTC
    That looks rather like a representation of the aggregate/composite pattern - a list being an object (which, as tobyink has already pointed out, has an unusual name - LocalLB::ObjectStatus[]) which itself contains a number of other objects (of class LocalLB::ObjectStatus).

    In order to access the contained objects, I suggest that you have a look at the containing class (LocalLB::ObjectStatus[]) to determine the name(s) of the accessor methods - which will, I would guess, follow the form of the GoF Iterator pattern e.g. get_next(), has_next() etc.

    HTH ,

    A user level that continues to overstate my experience :-))

      Thank you all for your help.

      It took me a while to digest what you had all posted, but I have now worked it out, and it seems so simple now!

      In the end all I needed was this:

      foreach ($ic->get_ltm_pool_members_status($pool)) { foreach (@{$_}) { print "$_->{enabled_status}\n"; }

      Thanks

      Darren