Hi
I have a strange problem with my OOPerl module and the AUTLOAD method. Let me explain.... I have a big hash that contains attributes...
my %_attribute_properties = ( _probeset_id => ['????', 'read.required'], ... _affy_align => [ ['????'] , 'read.write.noinit' ] _exons_map => [ { } , 'read.write.noinit' ] ... );
Note that this attributes contains values of different type.
Now I have an AUTOLOAD method to get and set the attributes values. Concept of AUTOLOAD is :
Proble is that the first time that i call:
my %hash = $probeset -> get_exons_map I recieve an error (scalar found where list expected).
Second time no problem, I recieve thet correct type (hash)
Seems that the AUTOLOAD can't access valute type (but only the scalar pointer) at the first time! How can resolve it?

# AUTOLOAD Accesors if ($operation eq 'get') { # can i read the attribute? unless ($self -> _permissions ($attribute, 'read')) { die ("You don't have read permission for $attribute"); } # # Install accessor definition in the symbol table # How AUTOLOAD work: *{$VAR} give access to the symbol definit +ion table so, # the second time that the method get_name is called AUTOLOAD +isn't called cause # get_name is saved in the symbol table *{$AUTOLOAD} = sub { my ($self) = @_; unless ($self -> _permissions($attribute, 'read')) { die ("$attribute does not have read permission!"); } # get the attribute value # TIE-HASH da inserire qui # The attribute could be a scalar or a reference to an arr +ay or hash if (ref($self -> {$attribute}) eq 'ARRAY') { return @{$self->{$attribute}}; } elsif (ref($self -> {$attribute}) eq 'HASH') { return %{$self->{$attribute}}; } else { return $self -> {$attribute}; } }; }elsif ($operation eq 'set') { # Verify if you can set the attribute unless ($self -> _permissions($attribute, 'write')) { die ("$attribute does not have write permission!"); } # set the attribute value $self -> {$attribute} = $newvalue; # Install this mutator in the symbol table *{$AUTOLOAD} = sub { my ($self, $newvalue) = @_; unless ($self -> _permissions($attribute, 'write')) { die ("$attribute does not have write permission!"); } $self -> {$attribute} = $newvalue; }; } # Turn strict refs on use strict 'refs'; # Return the attribute value return $self -> {$attribute}; } # }}}

In reply to OO Perl and AUTOLOAD by tucano

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.