in reply to Re: Object oriented mess
in thread Object oriented mess

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; -------------------------------------------

Replies are listed 'Best First'.
Re^3: Object oriented mess
by dragonchild (Archbishop) on Apr 13, 2005 at 14:52 UTC
    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).
Re^3: Object oriented mess
by Joost (Canon) on Apr 13, 2005 at 14:52 UTC
      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
        The standard way is to put those "global" routines in their own module (that is, in Some.pm file with package Some;).

        That way you can either refer to them directly, as Some::function() or you can use Exporter to export them to other namespaces that want them (and they will also have some control over which functions/variables they'll import, if you set up Exporter correctly).