require Net::Curl; Then, the following (assume I have use strict) fails withwhile the following does notBareword "Net::Curl::Easy::new" not allowed while "strict subs" in use +<?c> <c> my $c = Net::Curl::Easy::new;my $c = Net::Curl::Easy->new;
That's because require is a runtime directive, and strict is compile time. During the parse of the script it is not distinguishable whether Net::Curl::Easy::new is a subroutine call or a bareword. Add parens to disambiguate:
my $c = Net::Curl::Easy::new();
or wrap the require statement into a BEGIN block:
BEGIN { require Net::Curl::Easy }
which loads, compiles and executes Net/Curl/Easy.pm during the parse, and thus makes known Net::Curl::Easy::new as being a subroutine in perl's symbol table.
But then, if Net::Curl::Easy::new is not insentitive to be called as a class method or a function, (i.e. it takes arguments and doesn't validate them proper), you may have to pass the classname, as LanX noted:
my $c = Net::Curl::Easy::new( q(Net::Curl::Easy) );
- or not. Documentation or source code should reveal that.
In reply to Re: Why does Net::Curl::Easy->new work but Net::Curl::Easy::new does NOT?
by shmem
in thread Why does Net::Curl::Easy->new work but Net::Curl::Easy::new does NOT?
by YenForYang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |