Folks,

I'd like to use an object created using Object::InsideOut that would store in its array (of type LIST) elements which are themselves objects. I'd like that upon object creation, that it takes a series of name strings and creates this list of other objects, each one having its own name.

This means calling new() for each object to create and using sequentially the names given for each in an array passed as parameter to $obj->new().

The main object would look like:

package Objects::Status; { use Object::InsideOut; my @statuses :Field('Standard' => 'statuses', Type => 'Objects::Stat +usElement'); my %init_args :InitArgs = ( 'STATUSES' => { 'Type' => 'LIST', 'Field' => \@statuses, 'Default' => 'empty', }, ); sub init :Init { my ($self, $args) = @_; $self->set(\@statuses, foreach my $value (keys @$args->{'STATUSES'}){ Objects::StatusElement->new('Name' => $value); } }

This object will store an array of the following object:

package Objects::StatusElement; { use Object::InsideOut; my @name :Field('Standard' => 'name'); my @status :Field('Standard' => 'status'); my @acknowledged :Field('Standard' => 'acknowledged'); my %init_args :InitArgs = ( 'NAME' => { 'Regex' => qr/^name$/i, 'Mandatory' => 1, 'Field' => \@name, }, 'STATUS' => { 'Regex' => qr/^status$/i, 'Default' => 'ERROR', 'Field' => \@status, }, 'ACKNOWLEDGED' => { 'Regex' => qr/^acknowledged$/i, 'Default' => 0, 'Type' => 'NUMERIC', 'Field' => \@acknowledged, }, ); }

What I have trouble with, is how to declare the initialization loop that will take each string given in the Status creation:

my $unitStatus = Objects::Status->new(statuses => ['DataFileFound', 'I +nfoFileFound', 'OtherStatus']);

... and create each StatusElement object as if the following was called repeatedly:

pushd @theObjectArray, Objects::StatusElement->new('Name' => 'DataFil +eFound'); pushd @theObjectArray, Objects::StatusElement->new('Name' => 'InfoFil +eFound'); pushd @theObjectArray, Objects::StatusElement->new('Name' => 'OtherSt +atus');

Or is it altogether not the right way to achieve this ?

Any suggestions welcomed ! - Thanks !


In reply to Object::InsideOut and LIST of objects by carcassonne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.