sasikumar has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am new to Mason programming with apache. I have a mason script that runs cool in the command line. But when i try to fetch the same script thru browser it runs fine for the first time. Frm the next it just throws a unexpected error.
error: Undefined subroutine &ASA::UIC_DBSTATUS::RetriveBuildStatus ca +lled at C:\perl-apache2\Apache2\mason\BuildMan\BuildStat.html line 8. context: ... 4: %use ASA::UIC_DBSTATUS; 5: %my %Table; 6: %my $status=new ASA::UIC_DBSTATUS(); 7: %print Dumper($status); 8: %$status->RetriveBuildStatus('ASA',\%Table); 9: <& footer.html &> 10: code stack: C:\perl-apache2\Apache2\mason\BuildMan\BuildStat.html:8
My Code
<& header.html, node=>2 &> %use strict; %use Data::Dumper; %use ASA::UIC_DBSTATUS; %my %Table; %my $status=new ASA::UIC_DBSTATUS(); %print Dumper($status); %$status->RetriveBuildStatus('ASA',\%Table); <& footer.html &>

Can any one throw lights on it.
Thanks
SasiKumar

20050328 Edit by castaway: Changed title from 'Masson and objects'

Replies are listed 'Best First'.
Re: Mason and objects
by bart (Canon) on Mar 23, 2005 at 16:25 UTC
    Is ASA::UIC_DBSTATUS a proprietary module? Google never heard of it. Anyway, "RetriveBuildStatus" seems like a typo to me, I'd rather expect something spelled "RetrieveBuildStatus".
Re: Mason and objects
by Fletch (Bishop) on Mar 23, 2005 at 17:22 UTC

    Strange, but:

    • Your use statements and global (to the component) variable declarations really should go inside a <%once> block.
    • Likewise setting $status should be done in an <%init> block.
    • It'd be more Masonic to use <% Dumper( $status ) %> rather than printing.
    • A better way to wrap components in a header and footer is to use the autohandler mechanism.
    <pre> <% Dumper($status) %> </pre> % $status->RetriveBuildStatus('ASA',\%Table); <%once> use strict; use Data::Dumper; use ASA::UIC_DBSTATUS; my %Table; my $status </%once> <%init> $status = ASA::UIC_DBSTATUS->new(); %Table = (); </%init>
Re: Mason and objects
by sasikumar (Monk) on Mar 23, 2005 at 18:35 UTC
    ya Fletch,

    Its pretty strange. I did all the changes that u have specified even still i get the same problem.It works for first time then it fails with the same error
    <pre> <% Dumper($status) %> <% Dumper(%Table) %> </pre> <& footer.html &> <%init> my $status; $status = ASA::UIC_DBSTATUS->new(); my %Table = (); $status->RetriveBuildStatus($div,\%Table); </%init> <%once> use strict; use ASA::UIC_DBSTATUS qw/RetriveBuildStatus/; </%once> <%args> $div=>"ASA";
    Thanks
    SasiKumar
Re: Mason and objects
by sasikumar (Monk) on Mar 23, 2005 at 16:29 UTC
    bart yes its a proprietary module.
    sub RetriveBuildStatus($) { my $self=shift; my $division=shift; my $StatusRef=shift; my $sth=$self->{'dbh'}->prepare("select * from builds where build_n +ame='ASA150_NB'") || return "Unable to prepare $DBI::errstr"; .... .... } return 1;

    The same mason code works well with a new browser for the first time. If u refresh it next time Opps its gone

    Thanks
    SasiKumar