Hello,
I'm trying to use Class::Struct, but I'm missing something (probably at a more general level...).
If I run this code I see that if I write a method to override the one created by the Class:Struct module, the attribute name (new_id, in the following) has not the package name prepended. So when I try to access it it is undefined.
Could you please provide me some clue ?
TIA
use strict; use warnings; use Data::Dumper; package Datum; use Class::Struct; struct (Datum => { id => '$', new_id => '$', }); sub Datum::new_id { my $self = shift(); if (@_) { $self->{new_id} = $_[0] + 1; } return $self->{new_id}; } package Dataset; use Class::Struct; struct (Dataset => { member => '$', }); sub Dataset::dump_new_id { my $self = shift(); print "\n\n new_id is undefined\n\n" unless defined ($self->{new_i +d}); } package main; my $dataset = Dataset->new; my $datum = Datum->new; $datum->id(3); $datum->new_id(3); $dataset->member($datum); $dataset->dump_new_id; die Dumper($dataset);
That gives:
new_id is undefined $VAR1 = bless( { 'Dataset::member' => bless( { 'Datum::id' => 3, 'new_id' => 4, 'Datum::new_id' => unde +f }, 'Datum' ) }, 'Dataset' );

In reply to Overriding methods in Class::Struct by Anonymous Monk

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.