Tải bản đầy đủ (.pdf) (72 trang)

Perl in a Nutshell phần 5 pot

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (6.44 MB, 72 trang )

Chapter 8
Standard Modules

8.15 B::Disassembler
Disassembles Perl bytecode.
8.14 B::Deparse 8.16 B::Lint
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.15 B::Disassembler
[2/7/2001 10:31:09 PM]
Chapter 8
Standard Modules

8.16 B::Lint
Provides program checking for Perl programs, equivalent to running Perl with the -w option. Named after
the Unix lint program for checking C programs. Invoked as:
perl -MO=Lint[,options] program
program is the name of the Perl program to be checked. The options are separated by commas and
follow normal backend option conventions. Most of the options are lint-check options, where each option
is a word specifying one lint check. Preceding an option with no- turns off that option. Options specified
later override earlier options. There is also one non-lint-check option, -u. Here is the list of available
options:
all
Turns all warnings on.
context
Warns whenever an array is used in implicit scalar context.
dollar-underscore
Warns whenever $_ is explicitly used anywhere or whenever it is used as the implicit argument of
a print statement.
implicit-read
Warns whenever an operation implicitly reads a Perl special variable.


implicit-write
Warns whenever an operation implicitly writes to a Perl special variable.
none
Turns off all warnings.
private-names
Warns whenever any variable, subroutine, or method name lives in a non-current package but
begins with an underscore (_); doesn't warn about an underscore as a single-character name, e.g.,
$_.
[Chapter 8] 8.16 B::Lint
(1 of 2) [2/7/2001 10:31:11 PM]
regexp-variables
Warns whenever one of the regular-expression variables $', $&, or $` is used.
-u Package
Normally checks only the main program code and all subroutines defined in package main; -u lets
you specify other packages to be checked.
undefined-subs
Warns whenever an undefined subroutine is invoked.
8.15 B::Disassembler 8.17 B::Showlex
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.16 B::Lint
(2 of 2) [2/7/2001 10:31:11 PM]
Chapter 8
Standard Modules

8.17 B::Showlex
Shows lexical variables used in functions or files. Invoke as:
perl -MO=Showlex[,sub] filename
If sub is provided and is the name of a subroutine in file filename, B::Showlex prints the lexical
variables used in that subroutine. Otherwise, it prints the file-scope lexicals in filename.

8.16 B::Lint 8.18 B::Stackobj
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.17 B::Showlex
[2/7/2001 10:31:12 PM]
Chapter 8
Standard Modules

8.18 B::Stackobj
Serves as a helper module for the CC backend.
8.17 B::Showlex 8.19 B::Terse
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.18 B::Stackobj
[2/7/2001 10:31:14 PM]
Chapter 8
Standard Modules

8.19 B::Terse
Walks the Perl syntax tree, printing terse information about the ops. Invoke as:
perl -MO=Terse[,exec] filename
If exec is specified, walks the tree in execution order instead of syntax order.
8.18 B::Stackobj 8.20 B::Xref
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.19 B::Terse
[2/7/2001 10:31:15 PM]
Chapter 8
Standard Modules


8.20 B::Xref
Perl compiler backend that generates a cross-reference listing of variables, subroutines, and formats in a
Perl program. Results are grouped by file, then subroutine, then package, then objects within the package
with line numbers. The line numbers are given as a comma-separated list. A line number may be
preceded by one of the following code letters:
Code Meaning
%
Subroutine or method call
f
Format definition
i Introduction, e.g., a lexical defined with my
s
Subroutine definition
Invoke B::Xref like this:
perl -MO=Xref[,options] program
program is the Perl program whose cross-reference you want. Options are separated by commas and
follow normal backend option conventions. The possible options are:
-D
Specifies internal debug options. Most useful if specified with -r option. Debug options are:
O
Prints each operator as it's being processed, in the execution order of the program.
t
Prints the object on the top of the stack as it is being tracked.
-ofilename
Sends output to filename instead of STDOUT.
-r
Produces raw output in machine-readable form for each definition or use of a variable, subroutine,
or format.
[Chapter 8] 8.20 B::Xref
(1 of 2) [2/7/2001 10:31:17 PM]

8.19 B::Terse 8.21 base
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.20 B::Xref
(2 of 2) [2/7/2001 10:31:17 PM]
Chapter 8
Standard Modules

8.21 base
Provides a shortcut for setting up @ISA. You can say:
use base qw(A B);
instead of:
BEGIN {
require Foo;
require Bar;
push @ISA, qw(Foo Bar);
}
8.20 B::Xref 8.22 Benchmark
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.21 base
[2/7/2001 10:31:18 PM]
Chapter 8
Standard Modules

8.22 Benchmark
Provides routines for timing the execution of your code and formatting the results. Inherits only from the
Exporter class. Its functions are:
new●
clearallcache●

clearcache●
debug●
disablecache●
enablecache●
timediff●
timeit●
timestr●
timethese●
timethis●
8.21 base 8.23 blib
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.22 Benchmark
[2/7/2001 10:31:19 PM]
Chapter 8
Standard Modules

8.23 blib
Pragma for testing programs against a package before the package has been installed. Given a directory
path, blib starts in that directory to look for a blib directory structure; if it doesn't find one there, it
works its way back up five levels. If no path is specified, it starts looking in the current directory.
blib is meant to be used from the command line:
perl -Mblib script [args ]
perl -Mblib=dir script [args ]
However, you can also call it from a Perl program:
use blib;
use blib 'dir';
8.22 Benchmark 8.24 Carp
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]

[Chapter 8] 8.23 blib
[2/7/2001 10:31:20 PM]
Chapter 8
Standard Modules

8.24 Carp
Provides routines for generating error messages. Its subroutines generally report errors from the
perspective of the calling program. Its functions are:
carp●
cluck●
confess●
croak●
8.23 blib 8.25 CGI
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.24 Carp
[2/7/2001 10:31:21 PM]
Chapter 8
Standard Modules

8.25 CGI
The CGI (Common Gateway Interface) library permits object-oriented web form creation and
processing. The CGI.pm module contains the bulk of functionality for CGI programming. Four
subclasses provide interfaces to various server environments and additional features. They are described
below. For complete information on how CGI works and a description of CGI.pm see Chapter 9, CGI
Overview, and Chapter 10, The CGI.pm Module.
8.24 Carp 8.26 CGI::Apache
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.25 CGI

[2/7/2001 10:31:22 PM]
Chapter 8
Standard Modules

8.26 CGI::Apache
Sets up the environment for using CGI.pm with the Perl-Apache API. The new constructor for this class
creates an Apache::CGI class object that interfaces to the API.
8.25 CGI 8.27 CGI::Carp
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.26 CGI::Apache
[2/7/2001 10:31:24 PM]
Chapter 8
Standard Modules

8.27 CGI::Carp
Creates Carp-like CGI routines for writing error messages to the HTTPD or other error log. Exports
functions for warn, die, carp, confess, and croak. The functions write timestamped error
messages to your server log or other output that you specify. See Section 8.24, "Carp" for details on the
Carp functions.
Two other functions are provided by this module. Neither are automatically exported, so you must
explicitly import them in use:
use CGI::Carp qw(carpout fatalsToBrowser);
carpout●
fatalsToBrowser●
8.26 CGI::Apache 8.28 CGI::Cookie
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.27 CGI::Carp
[2/7/2001 10:31:26 PM]

Chapter 8
Standard Modules

8.28 CGI::Cookie
Provides an interface to Netscape (HTTP/1.1) cookies that can be used in conjunction with CGI.pm or
independently. To use CGI::Cookie, you create a new cookie object with the constructor new. You can
then send the cookie to the browser in one of the following ways:
From a CGI script, create a Set-Cookie field in the HTTP header for each cookie you want to send
($c is the cookie object):
print "Set-Cookie: $c0";

With CGI.pm (see Chapter 10), use the header method with a -cookie argument:
print header(-cookie=>$c);

Using mod_perl (see Chapter 11, Web Server Programming with mod_perl), use the request
object's header_out method:
$r->header_out('Set-Cookie',$c);

The following methods are provided for CGI::Cookie:
new●
as_string●
domain●
expires●
fetch●
name●
parse●
path●
raw_fetch●
value●
8.27 CGI::Carp 8.29 CGI::Fast

[Chapter 8] 8.28 CGI::Cookie
(1 of 2) [2/7/2001 10:31:29 PM]
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.28 CGI::Cookie
(2 of 2) [2/7/2001 10:31:29 PM]
Chapter 8
Standard Modules

8.29 CGI::Fast
CGI interface for FastCGI. FastCGI is a type of gateway for web servers that improves performance by
loading scripts as persistently running processes. CGI::Fast provides a new constructor to create a CGI
object that runs in this environment. FastCGI requires both a server and a version of Perl that are
FastCGI enabled. See www.fastcgi.com for more information.
8.28 CGI::Cookie 8.30 CGI::Push
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.29 CGI::Fast
[2/7/2001 10:31:30 PM]
Chapter 8
Standard Modules

8.30 CGI::Push
Provides an interface to do server push operations, letting you rewrite pages whose content changes
regularly. A server push operation automatically sends updates to a page on a push-capable browser.
CGI::Push exports the function do_push to implement page redraws. This method can be used on a
CGI::Push object or on its own:
$q = new CGI::Push;
$q->do_push(-next_page => \&sub);
# or

do_push (-next_page => \&sub);
do_push requires one argument: a reference to a subroutine that will draw the next page. You may
optionally specify a subroutine that draws the last page and the interval between page updates. Additional
parameters to do_push are those that can be used with a CGI::headers object.
do_push●
8.29 CGI::Fast 8.31 CGI::Switch
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.30 CGI::Push
[2/7/2001 10:31:31 PM]
Chapter 8
Standard Modules

8.31 CGI::Switch
Provides a new method that tries to call new in each of the Apache::CGI, CGI::XA, and CGI classes,
returning the first CGI object that it successfully gets.
8.30 CGI::Push 8.32 Class::Struct
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.31 CGI::Switch
[2/7/2001 10:31:32 PM]
Chapter 8
Standard Modules

8.32 Class::Struct
Formerly named Class::Template; exports a single function, struct. struct takes a list of element
names and types, and optionally a class name, and creates a Perl class that implements a "struct-like" data
structure. It also creates a constructor method, new, for creating objects of the class (so a class created
this way must not itself define a new method).
Each element in the struct data has an accessor method, which is used to assign to the element and to

fetch its value. The default accessor can be overridden by declaring a sub of the same name in the
package. Each element's type can be scalar, array, hash, or class.
struct●
8.31 CGI::Switch 8.33 Config
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.32 Class::Struct
[2/7/2001 10:31:33 PM]
Chapter 8
Standard Modules

8.33 Config
Used to access configuration information. When Perl is built, the Configure script obtains and saves this
information in a hash, %Config, in Config.pm itself. Config checks to be sure it's running with the same
Perl version as the one that created the hash.
The index into the hash is the shell variable name. %Config is always exported; the following three
functions are exported on request:
config_sh●
config_vars●
myconfig●
8.32 Class::Struct 8.34 constant
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.33 Config
[2/7/2001 10:31:34 PM]
Chapter 8
Standard Modules

8.34 constant
A Perl pragma that declares compile-time constants with a given scalar or list value. By default, the value

is evaluated in list context, but you can override the default by specifying scalar.
use constant NAME1 => value1;
use constant NAME2 => scalar value2;
8.33 Config 8.35 CPAN
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
[Chapter 8] 8.34 constant
[2/7/2001 10:31:35 PM]
Chapter 8
Standard Modules

8.35 CPAN
Lets you access CPAN; search for a module, a bundle, an author, or a distribution; download a module or
distribution; install it; and make it. The CPAN module can be used either interactively from the
command line or programmatically:
perl -MCPAN -eshell; #run from the command line
Or:
use CPAN;
my $obj = CPAN::Shell->install('ExtUtils::MakeMaker');
This section describes the use of the CPAN module from a program. See Chapter 2, Installing Perl, for
information on using it interactively and for details of the available commands. These commands,
available interactively from the shell, are methods of the class CPAN::Shell. From a program, they are
available both as methods (e.g., CPAN::Shell->install( )) and as functions in the calling
package (e.g., install( )).
Each of the commands that produce listings of modules (r, autobundle, and u) returns a list of the
IDs of all modules within the list. The IDs of all objects available within a program are strings that can
be expanded to the corresponding real objects with the
CPAN::Shell->expand("Module",@things) method. expand returns a list of
CPAN::Module objects according to the @things arguments. In scalar context, it returns only the first
element of the list.

8.35.1 Session and Cache Managers
The CPAN module contains a session manager, which keeps track of objects that have been fetched,
built, and installed in the current session. No status is retained between sessions.
There is also a cache manager, which keeps track of disk space used and deletes extra space. The cache
manager keeps track of the build directory, $CPAN::Config->{build_dir}, and uses a simple
FIFO mechanism to delete directories below build_dir when they grow bigger than
$CPAN::Config->{build_cache}.
The original distribution files are kept in the directory
[Chapter 8] 8.35 CPAN
(1 of 3) [2/7/2001 10:31:38 PM]
$CPAN::Config->{keep_source_where}. This directory is not covered by the cache manager,
but must be controlled by the user. If the same directory is used as both build_dir and
keep_source_where, your sources are deleted with the same FIFO mechanism.
8.35.2 Bundles are
The CPAN module recognizes a bundle as a Perl module in the namespace Bundle:: that does not define
any functions or methods and usually contains only pod documentation. It starts like a Perl module with a
package declaration and a $VERSION variable. After that the pod section looks like any other pod with
the difference that it contains a special section that begins with:
=head1 CONTENTS
This section consists of lines like this:
Module_Name [Version_String] [- optional text]
where Module_Name is the name of a module (for example, Term::ReadLine), not the name of a
distribution file, and the version and text are optional. If there is text, it is preceded by a The
distribution of a bundle should follow the same convention as other distributions.
Bundles are treated specially in the CPAN package. When you tell CPAN to install a bundle, it installs
all the modules in the CONTENTS section of the pod. You can install your own bundles locally by
placing a conforming bundle file somewhere in your @INC path. The autobundle command available
in the shell interface does that for you by including all currently installed modules in a snapshot bundle
file (see Chapter 2).
8.35.3 Configuration

When the CPAN module is installed, a site-wide configuration file is created as CPAN/Config.pm. The
default values defined there can be overridden locally in the file CPAN/MyConfig.pm. You can store this
file in $HOME/.cpan/CPAN/MyConfig.pm, because $HOME/.cpan is added to the search path of the
CPAN module before the use or require statements. Chapter 2 lists the keys defined in the hash
reference $CPAN::Config and how to set and query them.
8.35.4 CD-ROM Support
The urllist parameter in the configuration table contains a list of URLs to be used for downloading. If the
list contains any file URLs, CPAN looks there first for files (except index files). So if you are using a
CD-ROM containing the CPAN contents, include the CD-ROM as a file URL at the end of urllist since it
is likely to be out-of-date. You can do this with:
o conf urllist push file://localhost/CDROM/CPAN
8.34 constant 8.36 CPAN::FirstTime
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
[Chapter 8] 8.35 CPAN
(2 of 3) [2/7/2001 10:31:38 PM]

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×