discore has asked for the wisdom of the Perl Monks concerning the following question:
And the Exported.pm module looks like this:#!/usr/bin/perl -w use strict; use DBI; use Exported qw(:All); my $db_info = "dbi:mysql:database;host=localhost"; our $dbh = DBI->connect($db_info, 'username', 'password', { PrintError + => 0 }) or die("Couldn't connect to database\n"); print "info: " , getdb() , "\n";
See that $main::dbh->selectrow_hashref()? I don't like it at all. Is there a better way to access the $dbh object from Exported.pm?#!/usr/bin/perl -w package Exported; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); # no default exports @EXPORT_OK = qw(&getdb); %EXPORT_TAGS = ( All => [qw(&getdb)] ); sub getdb { my $query = $main::dbh->selectrow_hashref("SELECT something FROM a +_table"); return $query->{'explanation'}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using objects in exported functions
by chromatic (Archbishop) on May 31, 2004 at 02:44 UTC | |
by Anonymous Monk on May 31, 2004 at 04:49 UTC | |
by chromatic (Archbishop) on May 31, 2004 at 05:47 UTC | |
by tkil (Monk) on May 31, 2004 at 06:00 UTC | |
|
Re: Using objects in exported functions
by Anomynous Monk (Scribe) on May 31, 2004 at 11:06 UTC |