in reply to Object oriented mess

Well, simply put, if adding use Client; breaks things, then the problem probably lies there. However, without knowing what "failure" means in this context (Do you get an error message? Does it work, but not return what you expect?) it's hard to say.

The first thing I suggest you do is read brian's Guide to Solving Any Perl Problem and follow its steps. I bet you find your answer around step 2 or 3.

Replies are listed 'Best First'.
Re^2: Object oriented mess
by longliveAJ (Acolyte) on Apr 13, 2005 at 14:39 UTC
    You are right ... its something to do in Client.pm..

    but thats such a simple module. Here is the exact code. Not sure if allowed to post so many lines..
    -----------------CLIENT.PM----------------- #!/usr/bin/perl package Client; use strict; # Include Database connect file here require '/home/www/www/cgi-bin/db_connect.pl'; require '/home/www/www/cgi-bin/global_subs.pl'; sub new { my($Class) = shift; my($ClientId) = shift; my $sth = $main::dbh->prepare ("SELECT client_fname, client_lname, email, password, status FROM client_info WHERE client_id = '$ClientId' "); $sth->execute();# or &PrintMessage("$BaseDir/templates", $ErrorGen +eralTmplt, "An Error has occurred.<p><A HREF=\"#\" onclick=\"history. +back()\">click here</A> to go back.</P>", "exit"); my $hashref = $sth->fetchrow_hashref (); my $Self = [ { "FirstName" => $hashref->{'client_fname'}, "LastName" => $hashref->{'client_lname'}, "PrimaryEmail" => $hashref->{'email'}, "Password" => $hashref->{'password'}, "Status" => $hashref->{'status'}, } ]; bless $Self, $Class; } sub get_status { my($Self) = shift; return $Self->{"Status"}; } 1; -------------------------------------------
      A few notes (including an answer to your problem):
      • Read up on placeholders in DBI. They will improve your database code, including fixing a few random bugs you may not have hit yet.
      • Add warnings (either with the 'use warnings;' pragma if your Perl is 5.6+ or the -w flag if not). It will find bugs for you.
      • You have a bug in your object. You are blessing an array reference (containing a single hash reference), but you are treating $self as a hash reference. This is a problem.
      • You will want to look at 'use lib' to set up a way of shortening those require statements.
      • Try varying the order you do the requires and the uses in your main script. Put the use before the requires then put the requires before the use. See if anything changes.
      • Rewrite your requires to be modules using Exporter. Then, you use them and it will do the right thing, even if you use them in modules you're using (which is the problem here).
        Hey guys,
        I have got some good pieces of advice here which is also leading to some kind of confusion.
        The problem resolved a little when I commented out the

        require ... require

        lines in Client.pm
        I am going to first heck out the Exporter module.
        But could someone tell me what is the best way to include a global(common file which has carries commonly used subroutines) file in all my packages in perl files.
        It seems that by using require and use together, is causing this error.
        Thanks