Hi,

Here is the kind of thing that is driving me nuts. Please see: 
http://perl.apache.org/docs/general/perl_reference/perl_reference.html#Remed
ies_for_Inner_Subroutines

If what this says is true, then either I don't have a closure type problem,
or else what is says isn't true. It says that 
if I have this situation, I will get a warning. I am not getting any
warnings, but I am getting this behaviour with my search queries "getting stuck"


The only thing I do is again, copied from the perltoot 


package Searches;

use strict;
use Carp;
use vars qw($dbh);
use gentimeid; # generate time id based
use Calc_Price; # get totals  
use warnings;
# use DBIx::XHTML_Table;  # maybe later
use QueryPrint;

#use Data::Dumper;



# These searches are restricted to user level searches, there will be a
admin level search for 
# managment reports 

$dbh = db_connect();


# requires a $q query object to be init.



sub new {
            my $self  = {};
            my $proto = shift;
            my $class = ref($proto) || $proto;
            $self->{queryobject}   = undef;
            $self->{isDomestic} = undef;
            $self->{isInternational} = undef;
            $self->{isShippingSame} = undef;
            $self->{CustIsInserted} = undef;
            $self->{OrderIsInserted} = undef;
            $self->{CustNum} = undef;
            $self->{OrderNum} = undef;
            bless ($self, $class);
            return $self;
}


sub queryobject {
          
          my $self = shift;
          if (@_) { $self->{queryobject} = shift }
          return $self->{queryobject};
        }


.... Other stuff not used yet



sub LookupOrder {

my $self = shift;
my $q = $self->{queryobject};
my $output = '';
my $hasparameter = 0;



... Build a query from CGI.pm vars passed in though queryobject





... 


$order_name_qu .= " ORDER BY $orderby "; # the query string is here


if ($hasparameter == 1) {  # if something was filled in the search form

        my $sth = $dbh->prepare($order_name_qu) or confess("Main search
failed $order_name_qu");
        $sth->execute() or confess("Main search failed $order_name_qu");  

        my $headers = $sth->{'NAME'};   

        my @rows    = $sth->fetchall_arrayref();

        my $resulthtml = new QueryPrint(ResultSet => @rows,
                                Action => 'customer',
                                ColumnList => $headers);

        my $html = $resulthtml->SetAction();  # sets a template type in the
QueryPrint module
        $output = $resulthtml->QueryPrint();  
        $sth->finish();
        #warn "QUERY - $order_name_qu";
        undef @rows;
        undef $resulthtml;
        undef $order_name_qu;
        return $output;

} else {
        

return "no query to do";        
        
}


Then this is all called from my CGI::Application module

sub customer_display{

my $self = shift;
my $q = $self->query();

my $customersearch = new Searches();
$customersearch->queryobject($q); # set the query

my $header = parse_header($self);
return $header . $customersearch->LookupCustName(); 

}


So going nuts now, where is the problem?  My QueryPrint module is pretty
much the same, so if this is ok, it should be as well. 


Thanks,

Eric 



>Are you using any modules that have subs with sub ref prototypes, like 
>Error.pm?  That can do it.
>
>>All I have read says that because I am using oop
>>modules and use strict along with use vars that should not happen.
>>
>
>It's actually really easy to create closures.  Here is a closure:
>
>my $holdtype = $q->param('holdstate');
>display_holdtype();
>
>sub display_holdtype {
>    print "holdtype: $holdtype in process $$\n";
>}
>
>This will always print whatever the value was the first time, no matter 
>what you change it to later.  (The first time for that process, that 
>is.)  Watch out for things like that.  You should always pass params 
>explicitly.
>
>>4. I know the way I have done these db connects is sloppy. But I can't seem
>>to find a better way. Could I make one db_connect sub,and inherite it all
>>though my modules? 
>>
>
>Make one sub that returns a database handle and use it from everywhere. 
> Doesn't need to be inherited, you can just stick it in a module that 
>all the other modules call.
>
>Hope some of that was helpful,
>Perrin
>

(250) 655 - 9513 (PST Time Zone)

"Inquiry is fatal to certainty." -- Will Durant 




Reply via email to