⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exporter.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
package Exporter;require 5.006;# Be lean.#use strict;#no strict 'refs';our $Debug = 0;our $ExportLevel = 0;our $Verbose ||= 0;our $VERSION = '5.62';our (%Cache);# Carp does this now for us, so we can finally live w/o Carp#$Carp::Internal{Exporter} = 1;sub as_heavy {  require Exporter::Heavy;  # Unfortunately, this does not work if the caller is aliased as *name = \&foo  # Thus the need to create a lot of identical subroutines  my $c = (caller(1))[3];  $c =~ s/.*:://;  \&{"Exporter::Heavy::heavy_$c"};}sub export {  goto &{as_heavy()};}sub import {  my $pkg = shift;  my $callpkg = caller($ExportLevel);  if ($pkg eq "Exporter" and @_ and $_[0] eq "import") {    *{$callpkg."::import"} = \&import;    return;  }  # We *need* to treat @{"$pkg\::EXPORT_FAIL"} since Carp uses it :-(  my($exports, $fail) = (\@{"$pkg\::EXPORT"}, \@{"$pkg\::EXPORT_FAIL"});  return export $pkg, $callpkg, @_    if $Verbose or $Debug or @$fail > 1;  my $export_cache = ($Cache{$pkg} ||= {});  my $args = @_ or @_ = @$exports;  local $_;  if ($args and not %$export_cache) {    s/^&//, $export_cache->{$_} = 1      foreach (@$exports, @{"$pkg\::EXPORT_OK"});  }  my $heavy;  # Try very hard not to use {} and hence have to  enter scope on the foreach  # We bomb out of the loop with last as soon as heavy is set.  if ($args or $fail) {    ($heavy = (/\W/ or $args and not exists $export_cache->{$_}               or @$fail and $_ eq $fail->[0])) and last                 foreach (@_);  } else {    ($heavy = /\W/) and last      foreach (@_);  }  return export $pkg, $callpkg, ($args ? @_ : ()) if $heavy;  local $SIG{__WARN__} = 	sub {require Carp; &Carp::carp};  # shortcut for the common case of no type character  *{"$callpkg\::$_"} = \&{"$pkg\::$_"} foreach @_;}# Default methodssub export_fail {    my $self = shift;    @_;}# Unfortunately, caller(1)[3] "does not work" if the caller is aliased as# *name = \&foo.  Thus the need to create a lot of identical subroutines# Otherwise we could have aliased them to export().sub export_to_level {  goto &{as_heavy()};}sub export_tags {  goto &{as_heavy()};}sub export_ok_tags {  goto &{as_heavy()};}sub require_version {  goto &{as_heavy()};}1;__END__=head1 NAMEExporter - Implements default import method for modules=head1 SYNOPSISIn module YourModule.pm:  package YourModule;  require Exporter;  @ISA = qw(Exporter);  @EXPORT_OK = qw(munge frobnicate);  # symbols to export on requestor  package YourModule;  use Exporter 'import'; # gives you Exporter's import() method directly  @EXPORT_OK = qw(munge frobnicate);  # symbols to export on requestIn other files which wish to use YourModule:  use ModuleName qw(frobnicate);      # import listed symbols  frobnicate ($left, $right)          # calls YourModule::frobnicateTake a look at L</Good Practices> for some variantsyou will like to use in modern Perl code.=head1 DESCRIPTIONThe Exporter module implements an C<import> method which allows a moduleto export functions and variables to its users' namespaces. Many modulesuse Exporter rather than implementing their own C<import> method becauseExporter provides a highly flexible interface, with an implementation optimisedfor the common case.Perl automatically calls the C<import> method when processing aC<use> statement for a module. Modules and C<use> are documentedin L<perlfunc> and L<perlmod>. Understanding the concept ofmodules and how the C<use> statement operates is important tounderstanding the Exporter.=head2 How to ExportThe arrays C<@EXPORT> and C<@EXPORT_OK> in a module hold lists ofsymbols that are going to be exported into the users name space bydefault, or which they can request to be exported, respectively.  Thesymbols can represent functions, scalars, arrays, hashes, or typeglobs.The symbols must be given by full name with the exception that theampersand in front of a function is optional, e.g.    @EXPORT    = qw(afunc $scalar @array);   # afunc is a function    @EXPORT_OK = qw(&bfunc %hash *typeglob); # explicit prefix on &bfuncIf you are only exporting function names it is recommended to omit theampersand, as the implementation is faster this way.=head2 Selecting What To ExportDo B<not> export method names!Do B<not> export anything else by default without a good reason!Exports pollute the namespace of the module user.  If you must exporttry to use @EXPORT_OK in preference to @EXPORT and avoid short orcommon symbol names to reduce the risk of name clashes.Generally anything not exported is still accessible from outside themodule using the ModuleName::item_name (or $blessed_ref-E<gt>method)syntax.  By convention you can use a leading underscore on names toinformally indicate that they are 'internal' and not for public use.(It is actually possible to get private functions by saying:  my $subref = sub { ... };  $subref->(@args);            # Call it as a function  $obj->$subref(@args);        # Use it as a methodHowever if you use them for methods it is up to you to figure outhow to make inheritance work.)As a general rule, if the module is trying to be object orientedthen export nothing. If it's just a collection of functions then@EXPORT_OK anything but use @EXPORT with caution. For function andmethod names use barewords in preference to names prefixed withampersands for the export lists.Other module design guidelines can be found in L<perlmod>.=head2 How to ImportIn other files which wish to use your module there are three basic ways forthem to load your module and import its symbols:=over 4=item C<use ModuleName;>This imports all the symbols from ModuleName's @EXPORT into the namespaceof the C<use> statement.=item C<use ModuleName ();>This causes perl to load your module but does not import any symbols.=item C<use ModuleName qw(...);>This imports only the symbols listed by the caller into their namespace.All listed symbols must be in your @EXPORT or @EXPORT_OK, else an erroroccurs. The advanced export features of Exporter are accessed like this,but with list entries that are syntactically distinct from symbol names.=backUnless you want to use its advanced features, this is probably all youneed to know to use Exporter.=head1 Advanced features=head2 Specialised Import ListsIf any of the entries in an import list begins with !, : or / thenthe list is treated as a series of specifications which either add toor delete from the list of names to import. They are processed left toright. Specifications are in the form:    [!]name         This name only    [!]:DEFAULT     All names in @EXPORT    [!]:tag         All names in $EXPORT_TAGS{tag} anonymous list    [!]/pattern/    All names in @EXPORT and @EXPORT_OK which matchA leading ! indicates that matching names should be deleted from thelist of names to import.  If the first specification is a deletion itis treated as though preceded by :DEFAULT. If you just want to importextra names in addition to the default set you will still need toinclude :DEFAULT explicitly.e.g., Module.pm defines:    @EXPORT      = qw(A1 A2 A3 A4 A5);    @EXPORT_OK   = qw(B1 B2 B3 B4 B5);    %EXPORT_TAGS = (T1 => [qw(A1 A2 B1 B2)], T2 => [qw(A1 A2 B3 B4)]);    Note that you cannot use tags in @EXPORT or @EXPORT_OK.    Names in EXPORT_TAGS must also appear in @EXPORT or @EXPORT_OK.An application using Module can say something like:    use Module qw(:DEFAULT :T2 !B3 A3);Other examples include:    use Socket qw(!/^[AP]F_/ !SOMAXCONN !SOL_SOCKET);    use POSIX  qw(:errno_h :termios_h !TCSADRAIN !/^EXIT/);Remember that most patterns (using //) will need to be anchoredwith a leading ^, e.g., C</^EXIT/> rather than C</EXIT/>.You can say C<BEGIN { $Exporter::Verbose=1 }> to see how thespecifications are being processed and what is actually being importedinto modules.=head2 Exporting without using Exporter's import methodExporter has a special method, 'export_to_level' which is used in situationswhere you can't directly call Exporter's import method. The export_to_levelmethod looks like:    MyPackage->export_to_level($where_to_export, $package, @what_to_export);where $where_to_export is an integer telling how far up the calling stackto export your symbols, and @what_to_export is an array telling whatsymbols *to* export (usually this is @_).  The $package argument iscurrently unused.For example, suppose that you have a module, A, which already has animport function:    package A;    @ISA = qw(Exporter);    @EXPORT_OK = qw ($b);    sub import    {	$A::b = 1;     # not a very useful import method    }and you want to Export symbol $A::b back to the module that called package A. Since Exporter relies on the import method to work, via inheritance, as it stands Exporter::import() will never get called. Instead, say the following:    package A;    @ISA = qw(Exporter);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -