Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Declare a separate global namespaceTest whether a value, variable ... (Berikutnya)
Keywords altering or affecting scoping of identifiers

Load in a module at compile time

Daftar Isi

  • use Module VERSION LIST

  • use Module VERSION
  • use Module LIST
  • use Module
  • use VERSION

    Imports some semantics into the current package from the named module,generally by aliasing certain subroutine or variable names into yourpackage. It is exactly equivalent to

    1. BEGIN { require Module; Module->import( LIST ); }

    except that Module must be a bareword.The importation can be made conditional; see if.

    In the peculiar use VERSION form, VERSION may be either a positivedecimal fraction such as 5.006, which will be compared to $], or a v-stringof the form v5.6.1, which will be compared to $^V (aka $PERL_VERSION). Anexception is raised if VERSION is greater than the version of thecurrent Perl interpreter; Perl will not attempt to parse the rest of thefile. Compare with require, which can do a similar check at run time.Symmetrically, no VERSION allows you to specify that you want a versionof Perl older than the specified one.

    Specifying VERSION as a literal of the form v5.6.1 should generally beavoided, because it leads to misleading error messages under earlierversions of Perl (that is, prior to 5.6.0) that do not support thissyntax. The equivalent numeric version should be used instead.

    1. use v5.6.1; # compile time version check
    2. use 5.6.1; # ditto
    3. use 5.006_001; # ditto; preferred for backwards compatibility

    This is often useful if you need to check the current Perl version beforeuseing library modules that won't work with older versions of Perl.(We try not to do this more than we have to.)

    use VERSION also enables all features available in the requestedversion as defined by the feature pragma, disabling any featuresnot in the requested version's feature bundle. See feature.Similarly, if the specified Perl version is greater than or equal to5.11.0, strictures are enabled lexically aswith use strict. Any explicit use ofuse strict or no strict overrides use VERSION, even if it comesbefore it. In both cases, the feature.pm and strict.pm files arenot actually loaded.

    The BEGIN forces the require and import to happen at compile time. Therequire makes sure the module is loaded into memory if it hasn't beenyet. The import is not a builtin; it's just an ordinary static methodcall into the Module package to tell the module to import the list offeatures back into the current package. The module can implement itsimport method any way it likes, though most modules just choose toderive their import method via inheritance from the Exporter class thatis defined in the Exporter module. See Exporter. If no importmethod can be found then the call is skipped, even if there is an AUTOLOADmethod.

    If you do not want to call the package's import method (for instance,to stop your namespace from being altered), explicitly supply the empty list:

    1. use Module ();

    That is exactly equivalent to

    1. BEGIN { require Module }

    If the VERSION argument is present between Module and LIST, then theuse will call the VERSION method in class Module with the givenversion as an argument. The default VERSION method, inherited fromthe UNIVERSAL class, croaks if the given version is larger than thevalue of the variable $Module::VERSION.

    Again, there is a distinction between omitting LIST (import calledwith no arguments) and an explicit empty LIST () (import notcalled). Note that there is no comma after VERSION!

    Because this is a wide-open interface, pragmas (compiler directives)are also implemented this way. Currently implemented pragmas are:

    1. use constant;
    2. use diagnostics;
    3. use integer;
    4. use sigtrap qw(SEGV BUS);
    5. use strict qw(subs vars refs);
    6. use subs qw(afunc blurfl);
    7. use warnings qw(all);
    8. use sort qw(stable _quicksort _mergesort);

    Some of these pseudo-modules import semantics into the currentblock scope (like strict or integer, unlike ordinary modules,which import symbols into the current package (which are effectivethrough the end of the file).

    Because use takes effect at compile time, it doesn't respect theordinary flow control of the code being compiled. In particular, puttinga use inside the false branch of a conditional doesn't prevent itfrom being processed. If a module or pragma only needs to be loaded conditionally, this can be done using the if pragma:

    1. use if $] < 5.008, "utf8";
    2. use if WANT_WARNINGS, warnings => qw(all);

    There's a corresponding no declaration that unimports meanings importedby use, i.e., it calls unimport Module LIST instead of import.It behaves just as import does with VERSION, an omitted or empty LIST, or no unimport method being found.

    1. no integer;
    2. no strict 'refs';
    3. no warnings;

    Care should be taken when using the no VERSION form of no. It isonly meant to be used to assert that the running Perl is of a earlierversion than its argument and not to undo the feature-enabling side effectsof use VERSION.

    See perlmodlib for a list of standard modules and pragmas. See perlrunfor the -M and -m command-line options to Perl that give usefunctionality from the command-line.

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Declare a separate global namespaceTest whether a value, variable ... (Berikutnya)