in reply to Re: cgi and own modules causing unspecified error
in thread cgi and own modules causing unspecified error

yes that's it. Expanding my example now, i get another error "Can't locate object method "new" via package "Hello" (perhaps you forgot to load "Hello"?)"


thats the new code:
Hello-2.pl
#!d:\perl\bin\perl.exe use lib 'S:\incubator\ex\Hello.pm'; print"Content-type:text/html;charset=UTF-8\n\n" ; my $obj = Hello->new( sample_data => 'hello world', more_data => 'blah blah blah' ); $obj->sample_method();
Hello.pm
#!d:\perl\bin\perl.exe package Hello; #SampleObject; sub new { my ($class, %args) = @_; return bless { %args }, $class; } sub sample_method { my ($self) = @_; print $self->{sample_data}; } 1;

Replies are listed 'Best First'.
Re^3: cgi and own modules causing unspecified error
by stevieb (Canon) on Jun 08, 2017 at 14:43 UTC

    Hey amitsq, the following is incorrect:

    use lib 'S:\incubator\ex\Hello.pm';

    You add the *path* to the use lib pragma, not the file:

    use lib 'S:\incubator\ex';

      And add use Hello; :)

      changed it, but it just looks worse since the error is again : The page cannot be displayed because an internal server error has occurred.
      current code in hello-2.pl:
      #!d:\perl\bin\perl.exe use lib 'S:\incubator\ex'; use Hello; print"Content-type:text/html;charset=UTF-8\n\n" ; my $obj = Hello->new( sample_data => 'hello world', more_data => 'blah blah blah' ); $obj->sample_method();
Re^3: cgi and own modules causing unspecified error
by marto (Cardinal) on Jun 08, 2017 at 14:46 UTC
    use lib 'S:\incubator\ex\Hello.pm';

    Add the directory in which modules reside, rather than the full path to the module. Also you still need to use it:

    use strict; use warnings; use lib '/home/marto/temp'; use Hello; my $obj = Hello->new( sample_data => 'hello world', more_data => 'blah blah blah' ); $obj->sample_method();

    Also: lib.

Re^3: cgi and own modules causing unspecified error
by hippo (Archbishop) on Jun 08, 2017 at 14:38 UTC
    Can't locate object method "new" via package "Hello" (perhaps you forgot to load "Hello"?)

    The hint is right - you did forget to load "Hello". See use.

      adding the line  use "Hello" leads again to the error " The page cannot be displayed because an internal server error has occurred."

        You need to start looking at the error log of the webserver, if you're using CGI consider CGI::Carp. If you are starting from scratch I suggest looking at Mojolicious::Lite rather than CGI, see the documentation of the latter for some reasons why.