I think the code gives a more specific example of what I am asking.
Accessor building:
Which I am happy with (but no doubt someone will prove TIMTOWODI! ;P)# -------------------------------------------------------------------- +---------- # OBJECT CREATION # -------------------------------------------------------------------- +---------- sub _create_accessors { my %OrderObjectFields = @_; foreach my $field (keys %OrderObjectFields) { my $default = $OrderObjectFields{ $field }; my $code = ' sub '.$field.' { my $value = (scalar @_>1? $_[0]->{"'.$field.'"} = $_[1 +] : $_[0]->{"'.$field.'"} + ); $value ="'.$default.'" unless defined $value; $value; }'; eval $code; die $@ if( $@ ); } } # -------------------------------------------------------------------- +---------- BEGIN { _create_accessors( 'order_no' => 0 , 'items_in_order' => '', 'supplier_list' => '', ); } # -------------------------------------------------------------------- +---------- # STANDARD OBJECT METHODS # -------------------------------------------------------------------- +---------- sub get { my( $self, $attribute ) = @_; return $self->{$attribute}; } # -------------------------------------------------------------------- +---------- sub set { my( $self, $attribute, $value ) = @_; $self->{$attribute} = $value; }
This is the code snippet which my question is based on:
Having reached this point in the code, I became unsure whether I would have to splice @$supplerList or in some other way rebuild it, and then reassign it with $self->setsub set_stock { my( $self, $supplier, $line, $stockLevel ) = @_; my $supplierList = (); my $supplierNumber = $supplier->supplier_id; # $supplierList will be a reference to an array of references to h +ashes. unless( $supplierList = $self->get('supplier_list') ) { die( "Cannot set stock level when supplier list is corrupt: $s +upplierList" ); } foreach my $supp (@$supplierList) { next unless( $supp->{supplier_id} == $supplierNumber ); my $reference = $line->reference; # Here is the update. $supp->{$reference} = $stockLevel; } }
I just feel that it is starting to look messy and smacks of just not being right. I'd love some guidance on approaching this problem.
The more I preview this, the more I feel I am missing something obvious .. *goes back to reading the panther book some more*
--
Graq
In reply to Storing Info with Accessors by graq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |