More poking and a little progress. It turns out that the module's subroutines 'get_categories' and 'get_users' were trying to access variables declared with 'our' in the main Mason page (e.g., 'our $dbh', the database connection handle). Removing that code got rid of the 'Undefined subroutine' error message.
Still puzzled: why did I get an 'Undefined subroutine' error message, instead of something telling me that the subroutine couldn't access a variable? I have updated the code below so that the main Mason page passes the database handle to the subroutine, like so: my %categories = get_categories($dbh); which works. But is there a better way? On 6/30/09 2:43 PM, "Michael Boudreau" <mboud...@ad.uchicago.edu> wrote: > Hi all, > > I'm stumped by a Mason component that was working fine and suddenly is broken > in a way I can't see. > > I'm building a small Mason app on Mac OS X 10.5.7 with Mason 1.4, Apache 2.2, > mod_perl 2.0.2, and Perl 5.8.8. > > Today I began moving subroutines out of the individual Mason pages and into a > module. All was working fine--the Mason pages were finding the subroutines > they needed--and then it stopped. > > Here's the beginning of my module: > > package UCP::Sfmail; > use strict; > our (@ISA, @EXPORT, $VERSION); > use Exporter; > $VERSION = 1.00; > @ISA = qw(Exporter); > @EXPORT = qw( get_categories get_users ); > > sub get_categories { > my %categories; > [snip] > return %categories; > } > ... > > And here's the beginning of the Mason page: > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <%init> > use DBI; > use UCP::Sfmail; > > # database credentials > my $dbsrc = "DBI:mysql:mydb:localhost"; > my $user = "myuser"; > my $pass = "mypass"; > my %attr = ( RaiseError => 0, PrintError => 0 ); > > our $dbh = DBI->connect($dbsrc, $user, $pass, \%attr) > or die "Cannot connect: $DBI::errstr"; > > # fatal errors or non-fatal warnings are displayed > # before any page content > our @fatal_errors; > our @warnings; > > # for drop-down menus and other display > my %categories = get_categories(); > my %users = get_users(); > > Now when I load this page, I get this error message: > >> Undefined subroutine &HTML::Mason::Commands::get_categories called at >> /Users/mrb/Sites/mason/sfmail_new/sfmail_new_inbox.html line 22. -- Michael R. Boudreau Senior Publishing Technology Analyst The University of Chicago Press 1427 E. 60th Street Chicago, IL 60637 (773) 753-3298 fax: (773) 753-3383 ------------------------------------------------------------------------------ _______________________________________________ Mason-users mailing list Mason-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mason-users