Why don't both versions of this code check the -c Perl check?

The method new Parse::RecDescenthas this prototype:

sub new ($$$)
{
   # code goes here
}

and if I create an object like this:

my $parser = Parse::RecDescent->new($grammar);

he will create a parser and the method will get 2 parameters "Parse :: RecDescent" and $ grammar, right? If I try to create an object like:

Parse::RecDescent::new("Parse::RecDescent",$grammar)

this will not let you say "Not enough arguments for Parse :: RecDescent :: new" and I understand this message. I pass only 2 parameters. However, I do not understand why the arrow version works.

Can you explain?

+3
source share
1 answer

, OO-. , , sub &, &sub(arg0, arg1..);

perldoc perlsub:

"&" , , . , , , , . . .

, , .

Parse::RecDescent::new("Parse::RecDescent", $grammar) , , ( ). , :

sub new
{
    my ($class, @args) = @_;
    die "Not enough arguments passed to constructor" if @args < 2;
    # ...
}

. .

+11

Source: https://habr.com/ru/post/1732617/


All Articles