Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What makes a module a pragmatic module?

Tags:

perl

I'm looking at the source of base.pm in the Perl distribution, and I don't see what distinguishes it from a "non-pragmatic" module. If use base is a "pragma", is it fundamentally different in any way from use Foo where Foo is any module?

like image 781
gcbenison Avatar asked Mar 14 '13 22:03

gcbenison


People also ask

What is the difference between package and module in Perl?

A Perl package is a collection of code which resides in its own namespace. Perl module is a package defined in a file having the same name as that of the package and having extension . pm. Two different modules may contain a variable or a function of the same name.

What is use in Perl script?

In Perl, the use keyword is exactly equivalent to the following: use Mymodule; #is the same as BEGIN { require Mymodule; Mymodule->import(); } So if you are not defining an import routine in your code (or inheriting from Exporter ), then your modules are not importing anything into test.pl.


1 Answers

There's no solid definition for pragma. The closest to something official is in perlpragma.

  • They usually modify the language or the behaviour of the parser.
  • Their effect is usually lexically scoped.

I personally believe those are requirements (and it seems that perlpragma does too), but core modules vars and subs are documented to be pragmas even though their effect isn't lexically scoped.

base and lib don't match either of the criteria. What they do is provide information to "Perl itself". I guess that also qualifies as a pragma.

I consider my module use syntax qw( loop ); to be pragmatic. (Shameless plug!)

like image 147
ikegami Avatar answered Nov 15 '22 18:11

ikegami