logo
down
shadow

Troubleshooting Perl CGI app - Can't locate object method "new" via package


Troubleshooting Perl CGI app - Can't locate object method "new" via package

By : Harrison T
Date : November 21 2020, 07:01 PM
hop of those help? I have inherited an old perl app that I'm trying to resurrect. Sadly I'm not a perl guy (and only a novice developer). I've had some success fixing other problems with this app by finding solutions online, but a solution to this has eluded me so far, so felt it was time to ask for advice.
code :
package APP::CGI;

[…]

use lib qw(/opt/app/htdocs/lib);
use lib qw(/opt/app/htdocs/lib/APP);
use lib qw(/opt/app/htdocs/lib/APP/Service);


Share : facebook icon twitter icon
Why does Perl's URI complain "Can't locate object method "host" via package "URI::_generic"'?

Why does Perl's URI complain "Can't locate object method "host" via package "URI::_generic"'?


By : Mohammad
Date : March 29 2020, 07:55 AM
With these it helps URI->new creates instances of a subclass of URI, depending on the scheme of the url you give it. Those subclasses might be URI::http, URI::file, URI::mailto, or something completely different. If URI doesn't have a specialized subclass for the kind of url you gave it, it'll create an instance of URI::_generic.
Each of those URI subclasses have different methods. URI::http happens to have a host method, but most others don't. You're calling ->host on something that isn't a URI::http or similar, and therefore doesn't have a host method.
Error: "Can't locate object method "new" via package" in Perl

Error: "Can't locate object method "new" via package" in Perl


By : erlong Fang
Date : March 29 2020, 07:55 AM
To fix the issue you can do I'm new to Perl, so I'm having some problems with OOP. , You need to have something like:
file: Player.pm
code :
package Player;
use strict;
use warnings;
sub new {
    ...
}
use strict;
use warnings;
use Player;
my $player = Player->new( ... args...);
package Player;
use strict;
use warnings;
use Method::Signatures::Simple;  # for automatic $self using "method" instead of the "sub"
use Mo;

has 'name';
has 'age';

method info {
        return "The player " . $self->name . " is " . $self->age . " years old.";
}
1;
use strict;
use warnings;
use feature 'say';
use Player;

my $player = Player->new(name => 'John', age => 15);

say $player->info();
The player John is 15 years old.
Perl can't locate object method "query_form" via package "URI::_foreign" at Geo::Coder::Google::V3.p

Perl can't locate object method "query_form" via package "URI::_foreign" at Geo::Coder::Google::V3.p


By : danioch835
Date : March 29 2020, 07:55 AM
should help you out The URI constructor creates an object instance specific to the scheme of the data passed to it. For http data, that is URI::http. However, if it's unable to determine a scheme, the final fall back is of class URI::_foreign.
Each of these subclasses have different abilities and features. As you've observed, the base class _foreign does not have an implementation of query_form.
code :
use strict;
use warnings;

use URI;

while (<DATA>) {
    chomp;

    my $u = URI->new($_);
    printf "%-13s - %s\n", ref($u), $u;
}

__DATA__
http://www.asdf.com
http://www.asdf.com/morestuff
http://////too_many_slashes_still_ok
ftp://ftp.asdf.com/
gopher://oldtimey.com/
unknown://www.asdf.com/
URI::http     - http://www.asdf.com
URI::http     - http://www.asdf.com/morestuff
URI::http     - http://////too_many_slashes_still_ok
URI::ftp      - ftp://ftp.asdf.com/
URI::gopher   - gopher://oldtimey.com/
URI::_foreign - unknown://www.asdf.com/
Perl 'can't locate object method "worksheets" via package "Spreadsheet::ParseExcel::Workbook"'

Perl 'can't locate object method "worksheets" via package "Spreadsheet::ParseExcel::Workbook"'


By : johnny dupree
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The workbooks() method was added in 0.43, six years ago. Since your version of Perl is rather old (11 years), it's likely your version of Spreadsheet::ParseExcel is also rather old.
You can check with:
code :
perl -MSpreadsheet::ParseExcel -wle 'print $Spreadsheet::ParseExcel::VERSION'
What is the meaning for the error "cant locate object method via package" in perl?

What is the meaning for the error "cant locate object method via package" in perl?


By : Lihkin Agarwal
Date : March 29 2020, 07:55 AM
will help you
You should add use strict and use warnings 'all' at the top of every Perl source file you write
code :
package ChocolateCake;

use strict;
use warnings 'all';

sub new {
    my $class = shift;

    bless {}, $class;
}

sub bake {
    print "The cake is baking\n";
}

sub freeze {
    print "The cake is freezing\n";
}

1;
package BirthdayCake;

use strict;
use warnings 'all';

use parent 'ChocolateCake';

sub new {
    my $class = shift;

    my $self = $class->SUPER::new(@_);
    $self->{candles} = 0;

    $self;
}

sub add_candles {
    my $self = shift;
    my $num_candles = shift;
    $self->{candles} += $num_candles;

    print "The cake has $self->{candles} candles\n";
}

sub candles {
    my $self = shift;

    $self->{candles};
}

1;
use strict;
use warnings 'all';
use feature 'say';

use BirthdayCake;

my $cake = BirthdayCake->new;

$cake->bake;

$cake->add_candles(10);
$cake->add_candles(20);

printf "My cake is a %s with %d candles\n", ref $cake, $cake->candles;
The cake is baking
The cake has 10 candles
The cake has 30 candles
My cake is a BirthdayCake with 30 candles
Related Posts Related Posts :
  • What does Perl's -p command-line switch do?
  • How do I issue an HTTP redirect with Perl's CGI.pm?
  • How can I write a Template.pm filter to generate PNG output from LaTeX source code?
  • Error: Cannot parse function definition from ' hello()' in Mytest.xs, line 9
  • What's the proper way to fork() in FastCGI?
  • How can I use Math::Business::EMA with DBI to calculate exponential moving averages in Perl?
  • How can I print the calling program/module inside a method in Perl?
  • Which module should I use to parse mediawiki text into a Perl data structure?
  • perl assign reference to subroutine
  • How can I efficiently group a large list of URLs by their host name in Perl?
  • How can I restore STDOUT after redirecting it to a file in a Perl script?
  • How can I parse this configuration file format (allowing comments) in Perl?
  • How To Avoid a Perl script calling an Another Perl Script
  • Perl - Internal File (create and execute)
  • How can I call a PL/Perl function from another PL/Perl function?
  • How can I terminate a system command with alarm in Perl?
  • When should I use a factory to wrap a constructor in Perl?
  • How can I extract sentences with a particular phrase, in Perl?
  • Getting the inner hash in Perl
  • Dequeue an array in perl with thread::queue
  • How do I tell perl to execute a piece of generated Perl code?
  • Why does a positive lookahead lead to captures in my Perl regex?
  • In a digital photo, how can I detect if a mountain is obscured by clouds?
  • How can I take a reference to specific hash value in Perl?
  • How can I determine which package my constructor was called from?
  • What does "!" mean before a variable in perl
  • How do I install Perl's Lingua::Lid?
  • How can I copy a directory but ignore some files in Perl?
  • How can I build something like Amazon S3 in Perl?
  • How can I get the high-res mtime for a symbolic link in Perl?
  • How can I get the ultimate URL without fetching the pages using Perl and LWP?
  • I want to replace last / by ,
  • How can I create a new file using a variable value as the name in Perl?
  • Why does my Perl CGI program fail with "Software error: ..."?
  • Strange regular expression
  • How can I handle -r=<pattern> with Perl's Getopt::Long?
  • Is there a way that I can force mod_perl to re-use buffer memory?
  • Can I pass a regex to isa() with Moose-based objects?
  • How can I tell Perl's IO::Socket::INET which interface to use?
  • How do I print a hash structure in Perl?
  • perl : can't require $value from other perl file and use it in 3rd perl file
  • What reasons could there be for converting Perl to Java?
  • What does perl -pe "s|$PASSWORD|<PASSWORD>|g"?
  • How to do unary and/reduction of bus to a bit in Perl?
  • How to resolve @INC related issue in Perl
  • Perl DBI case insensitive methods
  • Unable to get page via HTTPS with LWP::Simple in Perl
  • Using Perl's File::Basename to rename a file extension
  • using an array as a reference is deprecated in perl
  • How to get unicode code points in perl v5.24?
  • Get array in perl from json_encode
  • perl print to a file and STDOUT which is the file
  • How to process variable dimension array in Perl
  • How to fetch a one table from HTML source file using lwp module?
  • Using Win32::Env perl module, environment variable not setting permanently in windows
  • why doesn't make -C change $PWD as seen through a scripting language such as Perl?
  • Assign temp file from cgi and read it in .sh
  • Displaying 12-h time in Perl using DateTime
  • Using Perl to replace empty string with space
  • Why Perl ignores spaces between a sigil and variable name?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk