Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Re: exporter and multiple namespaces

by btrott (Parson)
on May 01, 2001 at 23:20 UTC ( [id://77086]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: exporter and multiple namespaces
in thread exporter and multiple namespaces

That sounds fine; particularly after seeing your intended interface I withdraw all thoughts about using an OO approach. :) One shouldn't have to instantiate an object just to die.

Anyway, though, would you mind posting some of your code? Is it possible that you have your functions in @EXPORT_OK and that you're not importing them explicitly? Just an idea.

Replies are listed 'Best First'.
Re: Re: Re: Re: exporter and multiple namespaces
by AidanLee (Chaplain) on May 01, 2001 at 23:38 UTC

    I'll see what I can do about extracting what I think are the relevant bits :)

    here is the gist of csLogs::Error.pm

    package Error; use Exporter (); @ISA = qw(Exporter); @EXPORT = qw( csWarn csDie ); use lib 'f:/projects/site/bin/config/'; use strict; use utf8; use csLogsConfig; #================================================== # Replacements for User-called warn and die #-------------------------------------------------- # to be used instead of warn() in application code sub csWarn { takes error class/severity and diagnostics info as parameters . . . } #-------------------------------------------------- # to be used instead of die() in application code sub csDie { very similar to csWarn, except that it exit()'s on completion . . . } #================================================== # Private Functions . . . #================================================== #Overload SIGWARN and SIGDIE BEGIN { sub csWarnHandle { much like csWarn except with default parameters } sub csDieHandle { much like csDie except with default parameters } $SIG{__WARN__} = \&csWarnHandle; $SIG{__DIE__} = \&csDieHandle; } #---- 1;

    here is pieces of csDB, which is a wrapper for the DBI

    package csDB; use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(QueryDB $dbh); use lib 'f:/projects/site/bin/config/'; use strict; use DBI; use csConfig; use csLogs::Error; our $dbh; #===================================================================== +===================================== # Database Connection BEGIN { $dbh = DBI->connect(csDBAuth()) or csDie( class=>csErrorClass('SERVER_DATABASE'),severity=>csErrorSca +le('CRITICAL'), message=>'Could not connect to database server', debug=>$DBI::errstr ); } END { $dbh->disconnect(); } #===================================================================== +===================================== sub QueryDB { $dbh->{RaiseError}=0; $dbh->{PrintError}=0; my $qstring = $_[0]; my $dbquery= $dbh->prepare("$qstring") or csDie( class=>csErrorClass('CODE_DATABASE'),severity=>csErrorScale +('SEVERE'), message=>'Database Query Preparation Error', debug=>$DBI::errstr ); $dbquery->execute or csDie( class=>csErrorClass('CODE_DATABASE'),severity=>csErrorScale +('SEVERE'), message=>'Database Query Execution Error', debug=>$DBI::errstr ); $dbh->{RaiseError}=1; $dbh->{PrintError}=1; return ($dbquery); } #===================================================================== +===================================== other handy functions . . .

    and finally the script that i was testing upon discovering this issue, csErrorLog_Parser

    use lib 'f:/projects/site/bin/config/'; use strict; use utf8; use csConfig; use csLogsConfig; use csLogs::Error; use csLogs::Event; use csDB; if (-f &csErrorLog) # file exists and needs to be processed { my $tmp_logfile = csPath('logs').'/errors'.time().'.log'; my $LOG = undef; #--------------------------------- # renaming the file assures that the processing # this script does doesn't interfere with normal logging. rename(&csErrorLog,$tmp_logfile) or csDie( class=>csErrorClass('CO +DE_FILE_IO'),severity=>csErrorScale('MODERATE'), message=>'Error Log Parser + could not rename log to a temporary file.', debug=>"original filename: + '".&csErrorLog."'\nnew filename: '$tmp_logfile'" ); open($LOG,$tmp_logfile) or csDie( class=>csErrorClass('CODE_FILE_I +O'),severity=>csErrorScale('MODERATE'), message=>'Error Log Parser + could not open the renamed log file.', debug=>"filename: '$tmp_lo +gfile'" ); #--------------------------------- # process the entries my $entries = process_errorlog($LOG); Event::NoteEvent( class=>csEventClass('TOOL_ACTION'),importance=>c +sEventScale('LOW'), message=>'Error Log Parser successfully processed the e +rror log', info=>"$entries log entries processed from '".&csErrorL +og."'" ); #--------------------------------- # with processing completed dispose of the temp log file. close($LOG); unlink($tmp_logfile) or csDie( class=>csErrorClass('CODE_FILE_IO') +,severity=>csErrorScale('MODERATE'), message=>'Error Log Parser + could remove the renamed log file.', debug=>"filename: '$tmp_lo +gfile'" ); } else # file doesn't exist and no processing was necessary { Event::NoteEvent( class=>csEventClass('TOOL_ACTION'),importance=>c +sEventScale('LOW'), message=>"Error Log Parser ran but '".&csErrorLog."' wa +s not found", info=>"parser assumes no errors have been logged since +the parser was last run." ); } #exit #===================================================================== +=========================== sub process_errorlog { my $LOG = $_[0]; my $entries = 0; # track num of entries processed. my $state = 'none'; #state of the parser; my ( $time, $class, $severity, $message, $debug ) = (); #--------------------------------- # walk the file while( <$LOG> ) { ....fun with regex's and such.... } if( $time ) { ....temporary inelegance to flush out the last record.... } return $entries; }
      Your original error message was that the function csErrorClass couldn't be found in the csDB package. And that makes sense from the above code, because that function is not defined anywhere, nor is it exported from csLogs::Error. Could that be your problem?

      Do you define this function in csLogs::Error, and if so, why are you not exporting it?

      @EXPORT = qw( csWarn csDie csErrorClass );

        thank you much. it had originally been in the Error.pm file, but i had moved it elsewhere and had forgotten to clean up my tracks.

        and for a moment there I thought I had an interesting problem :)

        here's an oddity. I fixed it so csErrorClass now resides in Error.pm. I am still getting this

        Undefined subroutine &csDB::csErrorClass called ...

        however i added this in csDB as a check right before the error occurs

        foreach ( sort keys %csDB::) { print $_."\n"; }

        so that i could see the symbols in the namespace. lo and behold:

        BEGIN END EXPORT EXPORT_FAIL EXPORT_OK GetLongLen ISA QueryDB SafeQuote SetLongLen VERSION csDBAuth csDie csErrorClass <----- there it is csErrorScale csPath dbh import

        leaving me generally confused

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://77086]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-03-28 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found