I'm having some trouble sending the appropriate parameters to HTML::Template.
I have a module fetching the data from a DB, as follows:
EDIT: I have verified that the data exists on the databas, and is in the format I'm expecting
sub get_account
{
my $acct_num = pop;
my $ar = $dbh->selectall_arrayref( 'SELECT * FROM account WHERE acco
+unt_number = ?', { Slice => {} }, $acct_num );
my ($account) = @$ar;
$account->{transactions} = \{get_transactions($account->{transaction
+s_id})};
$account->{owners} = get_owners( $account->{customers_id} );
return $account;
}
sub get_transactions
{
my $transactions_id = shift;
my $sql = <<'EOSQL';
SELECT s.transaction_date, type.name, s.amount, s.new_balance
FROM transactions t
JOIN single_transaction s ON t.single_transaction_id = s.id
JOIN transaction_type type ON s.transaction_type_id = type.id
WHERE t.id = ?
EOSQL
my $ar = $dbh->selectall_arrayref( $sql, undef, $transactions_id );
my @lines;
my $count = 1;
my %transac;
for ( @$ar )
{
my ($key, $type, $amount, $new_balance) = @$_;
$key =~ /\A(\d{4})-(\d{2})-(\d{2})/;
my $date = "$3\/$2\/$1";
my @line = ($count, $date, $type, $amount, $new_balance);
$transac{$key} = \@line;
$count++;
}
return \%transac;
}
And the CGI part:
my $template = HTML::Template->new( filename => 'atm_choose.tmpl', die
+_on_bad_params => 0 );
my $account_number = param( 'account_number' );
my $account = MyDB->get_account( $account_number );
$template->param( %$account );
print header, $template->output;
I'm having trouble with setting the transactions in $account->{transactions}. When set as a reference to anon hash, I have an ISA problem, when set as an anon hash, HTML Template complains I'm attempting to set the parameter as a scalar.
I attempted de-referencing the hash, but to no avail.
thank you.
UPDATE 31.03.2013
There seem to be far more bugs than expected in the code, I'm going to start this from scratch.