in reply to Re: silent failure with non-existant module
in thread silent failure with non-existant module

The filehandle is created using File::Temp like this:

my $tmpdir = File::Spec->tmpdir(); my ($filehandle, $filename) = File::Temp::tempfile( "generated_XXXXXX" +, DIR => $tmpdir, SUFFIX => '.xls', UNLINK => 1); confess "Error!" if !$filehandle; binmode $filehandle; #Spreadsheet::WriteExcel only worked with bin +mode

Replies are listed 'Best First'.
Re^3: silent failure with non-existant module
by kwaping (Priest) on Oct 17, 2006 at 15:49 UTC
    How does it get into that sub? Are you referring to it as a global, or do you pass it in as a parameter?

    I guess what I'm really getting at is that your example code might be a bit too stripped-down for us to accurately diagnose your issue. There appear to be quite a few significant gaps. Can you flesh out your example code a little more, or is that really your actual code?

    ---
    It's all fine and dandy until someone has to look at the code.

      This is a more complete version of the code. I have removed most of the internals of the function that generate the XL sheet and also all the functions in the module that are not used in the code.

      The function generate_xl is called from a function in a sub class of CGI::Application.

      package PackageName::GenerateXL; use strict; use warnings; use Carp; use Data::Dump qw( dump ); use English; use File::Temp; use File::Spec; use Params::Validate qw( :all ); use POSIX qw( strftime ); use Spreadsheet::WriteExcel; use CorrectModuleName::DatabaseRow; use CorrectModuleName::HashUtils qw( values_sorted_by_key ); use CorrectModuleName::SQLCreator; use CorrectModuleName::Database; #Global reference to a Database object my $global_database; sub generate_xl{ #validate parameters with Params::Validate my ( $sheet_name, $database, $parameters ) = validate_pos( @_, 1, { +isa => 'ERM::Database' }, { type => HASHREF, optional => 1 }, ); $global_database = $database; #Mapping between the supported sheets and the generate functions my %supported_sheets = ( vareregistrering => \&_generate_vareregistrering, nyvare => \&_generate_avtaleskjema_nyvare, #REMOVED IN EXAMPLE prisendring => \&_generate_avtaleskjema_prisendring, #REMOVED ); if ( !exists $supported_sheets{ $sheet_name } ) { confess "$sheet_name is not a supported sheet.\n"; } #open a temporary file on the server for workbook my $tmpdir = File::Spec->tmpdir(); my ($filehandle, $filename) = File::Temp::tempfile( "generated_XXXXX +X", DIR => $tmpdir, SUFFIX => '.xls', UNLINK => 1); confess "ERROR\n" if !$filehandle; binmode $filehandle; my $generated_workbook = Spreadsheet::WriteExcel->new($filehandle); #EXECUTION NEVER REACHES THIS POINT. $supported_sheets{$sheet_name}->($generated_workbook, $parameters); $generated_workbook->close(); close $filehandle; #read the whole file into a string. my $excel_string = ''; open( my $FILE, $filename); binmode $FILE; while ( my $line = <$FILE> ) { $excel_string .= $line } close $FILE; return $excel_string; } sub _generate_vareregistrering{ my ( $workbook, $parameters ) = validate_pos( @_, { isa => 'Spreadsh +eet::WriteExcel' }, { type => HASHREF } ); my $productid = $parameters->{ productid }; confess "Cannot generate a 'vareregistrerings' form without a produc +tid." if !defined $productid; #THE ERROR WITH THE WRONG NAME IS HERE, BUT EXECUTION NEVER REACHES +THIS POINT my $database_row = WrongModuleName::DatabaseRow->new( { tablename => + 'PRODUCT', conditions => { PRODUCTID => $productid }, database => $g +lobal_database, } ); #DO LOTS OF STUFF TO GENERATE THE XL SHEET BY CALLING FUNCTION ON $w +orkbook. } 1;

      By the way, thanks to the person that greatly improved the title.