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.


In reply to Re^4: silent failure with non-existant module by Anonymous Monk
in thread silent failure with non-existant module by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.