Hello, I'm having a problem getting a builder to run in a subclass. Whenever I try and run a script that calls $obj->{'manual_phone'} it comes back undefined and I'm not sure why. I thought this was supposed to be built when the accessor was called.
Anyways, here's what I have.
package Transaction; use Moose; use MyDB::Merchid; use Win32; has 'transaction_type' => ( is => 'rw', isa => 'Str', required => 1, ); has merch_info => ( is => 'ro', isa => 'Any', builder => '_build_merch_info', ); sub _build_merch_info { my $self = shift; my $snum = substr(Win32::NodeName, 5); return MyDB::Merchid->retrieve($snum); } 1; package MyDB; use strict; use warnings; use base 'Class::DBI'; MyDB->connection('dbi:ODBC:mydbsqldsn') || die "Couldn't connect to da +tabase: " . $DBI::errstr . "\n"; 1; package Transaction::CC; use Moose; extends(qw/Transaction/); has 'manual_phone' => ( is => 'ro', isa => 'Str', lazy_build => 1, ); sub _build_manual_phone { my $self = shift; if (! defined $self->{merch_info}) { die "ERROR: merch_info not defined\n"; } return $self->{merch_info}->MANUAL_NUMBER; } 1; package MyDB::Merchid; use strict; use warnings; use base 'MyDB'; MyDB::Merchid->table('MERCHID'); MyDB::Merchid->columns(All => qw/ COMPANY_NUMBER MERCHID_SIC_CODE MERCHID_QUAL_CODE MANUAL_NUMBER /); 1;
A snippet from the script:
my $obj = Transaction::CC->new( 'transaction_type' => 'Visa', ); print "\$obj->{'manual_phone'}: " . $obj->{'manual_phone'} . "\n";

In reply to Moose, Class::DBI, and builder by perldiverx

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.