What makes a module a pragmatic module?

I look at the source of base.pm in the Perl distribution and I don’t see what sets it apart from the “non-pragmatic” module. If use base is a "pragma", then it is fundamentally different from use Foo , where Foo is any module?

+8
perl
source share
2 answers

There is no hard definition for pragma. The closest to something official is in perlpragma .

  • Usually they change the language or behavior of the parser.
  • Their effect is usually lexically limited.

I personally think that these are requirements (and it seems that perlpragma too), but the main modules vars and subs are documented as pragmas, although their effect is not lexically limited.

base and lib don't match one of the criteria. What they do provides information to "Perl itself." I think it also qualifies as a pragma.

I believe my module use syntax qw( loop ); is pragmatic. (Shameless plugin!)

+7
source share

Although the name is often used in many contexts, I usually think of pragma as something that uses the hash of %^H , as described in perldoc perlpragma . This means that the main difference is that the action MUST be at compile time; use works, but require (not in BEGIN) does not work. This is the key difference between a “pragmatic module” (by this definition) and other modules. By this definition, none of vars , subs , base or lib are pragmas.

+1
source share

All Articles