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

📄 perllexwarn.1

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 1
📖 第 1 页 / 共 2 页
字号:
The current hierarchy is:.PP.Vb 10\&  all \-+\&       |\&       +\- closure\&       |\&       +\- deprecated\&       |\&       +\- exiting\&       |\&       +\- glob\&       |\&       +\- io \-\-\-\-\-\-\-\-\-\-\-+\&       |                |\&       |                +\- closed\&       |                |\&       |                +\- exec\&       |                |\&       |                +\- layer\&       |                |\&       |                +\- newline\&       |                |\&       |                +\- pipe\&       |                |\&       |                +\- unopened\&       |\&       +\- misc\&       |\&       +\- numeric\&       |\&       +\- once\&       |\&       +\- overflow\&       |\&       +\- pack\&       |\&       +\- portable\&       |\&       +\- recursion\&       |\&       +\- redefine\&       |\&       +\- regexp\&       |\&       +\- severe \-\-\-\-\-\-\-+\&       |                |\&       |                +\- debugging\&       |                |\&       |                +\- inplace\&       |                |\&       |                +\- internal\&       |                |\&       |                +\- malloc\&       |\&       +\- signal\&       |\&       +\- substr\&       |\&       +\- syntax \-\-\-\-\-\-\-+\&       |                |\&       |                +\- ambiguous\&       |                |\&       |                +\- bareword\&       |                |\&       |                +\- digit\&       |                |\&       |                +\- parenthesis\&       |                |\&       |                +\- precedence\&       |                |\&       |                +\- printf\&       |                |\&       |                +\- prototype\&       |                |\&       |                +\- qw\&       |                |\&       |                +\- reserved\&       |                |\&       |                +\- semicolon\&       |\&       +\- taint\&       |\&       +\- threads\&       |\&       +\- uninitialized\&       |\&       +\- unpack\&       |\&       +\- untie\&       |\&       +\- utf8\&       |\&       +\- void.Ve.PPJust like the \*(L"strict\*(R" pragma any of these categories can be combined.PP.Vb 2\&    use warnings qw(void redefine);\&    no warnings qw(io syntax untie);.Ve.PPAlso like the \*(L"strict\*(R" pragma, if there is more than one instance of the\&\f(CW\*(C`warnings\*(C'\fR pragma in a given scope the cumulative effect is additive..PP.Vb 5\&    use warnings qw(void); # only "void" warnings enabled\&    ...\&    use warnings qw(io);   # only "void" & "io" warnings enabled\&    ...\&    no warnings qw(void);  # only "io" warnings enabled.Ve.PPTo determine which category a specific warning has been assigned to seeperldiag..PPNote: In Perl 5.6.1, the lexical warnings category \*(L"deprecated\*(R" was asub-category of the \*(L"syntax\*(R" category. It is now a top-level categoryin its own right..Sh "Fatal Warnings".IX Xref "warning, fatal".IX Subsection "Fatal Warnings"The presence of the word \*(L"\s-1FATAL\s0\*(R" in the category list will escalate anywarnings detected from the categories specified in the lexical scopeinto fatal errors. In the code below, the use of \f(CW\*(C`time\*(C'\fR, \f(CW\*(C`length\*(C'\fRand \f(CW\*(C`join\*(C'\fR can all produce a \f(CW"Useless use of xxx in void context"\fRwarning..PP.Vb 1\&    use warnings;\&\&    time;\&\&    {\&        use warnings FATAL => qw(void);\&        length "abc";\&    }\&\&    join "", 1,2,3;\&\&    print "done\en";.Ve.PPWhen run it produces this output.PP.Vb 2\&    Useless use of time in void context at fatal line 3.\&    Useless use of length in void context at fatal line 7..Ve.PPThe scope where \f(CW\*(C`length\*(C'\fR is used has escalated the \f(CW\*(C`void\*(C'\fR warningscategory into a fatal error, so the program terminates immediately itencounters the warning..PPTo explicitly turn off a \*(L"\s-1FATAL\s0\*(R" warning you just disable the warningit is associated with.  So, for example, to disable the \*(L"void\*(R" warningin the example above, either of these will do the trick:.PP.Vb 2\&    no warnings qw(void);\&    no warnings FATAL => qw(void);.Ve.PPIf you want to downgrade a warning that has been escalated into a fatalerror back to a normal warning, you can use the \*(L"\s-1NONFATAL\s0\*(R" keyword. Forexample, the code below will promote all warnings into fatal errors,except for those in the \*(L"syntax\*(R" category..PP.Vb 1\&    use warnings FATAL => \*(Aqall\*(Aq, NONFATAL => \*(Aqsyntax\*(Aq;.Ve.Sh "Reporting Warnings from a Module".IX Xref "warning, reporting warning, registering".IX Subsection "Reporting Warnings from a Module"The \f(CW\*(C`warnings\*(C'\fR pragma provides a number of functions that are useful formodule authors. These are used when you want to report a module-specificwarning to a calling module has enabled warnings via the \f(CW\*(C`warnings\*(C'\fRpragma..PPConsider the module \f(CW\*(C`MyMod::Abc\*(C'\fR below..PP.Vb 1\&    package MyMod::Abc;\&\&    use warnings::register;\&\&    sub open {\&        my $path = shift;\&        if ($path !~ m#^/#) {\&            warnings::warn("changing relative path to /var/abc")\&                if warnings::enabled();\&            $path = "/var/abc/$path";\&        }\&    }\&\&    1;.Ve.PPThe call to \f(CW\*(C`warnings::register\*(C'\fR will create a new warnings categorycalled \*(L"MyMod::abc\*(R", i.e. the new category name matches the currentpackage name. The \f(CW\*(C`open\*(C'\fR function in the module will display a warningmessage if it gets given a relative path as a parameter. This warningswill only be displayed if the code that uses \f(CW\*(C`MyMod::Abc\*(C'\fR has actuallyenabled them with the \f(CW\*(C`warnings\*(C'\fR pragma like below..PP.Vb 4\&    use MyMod::Abc;\&    use warnings \*(AqMyMod::Abc\*(Aq;\&    ...\&    abc::open("../fred.txt");.Ve.PPIt is also possible to test whether the pre-defined warnings categories areset in the calling module with the \f(CW\*(C`warnings::enabled\*(C'\fR function. Considerthis snippet of code:.PP.Vb 1\&    package MyMod::Abc;\&\&    sub open {\&        warnings::warnif("deprecated", \&                         "open is deprecated, use new instead");\&        new(@_);\&    }\&\&    sub new\&    ...\&    1;.Ve.PPThe function \f(CW\*(C`open\*(C'\fR has been deprecated, so code has been included todisplay a warning message whenever the calling module has (at least) the\&\*(L"deprecated\*(R" warnings category enabled. Something like this, say..PP.Vb 4\&    use warnings \*(Aqdeprecated\*(Aq;\&    use MyMod::Abc;\&    ...\&    MyMod::Abc::open($filename);.Ve.PPEither the \f(CW\*(C`warnings::warn\*(C'\fR or \f(CW\*(C`warnings::warnif\*(C'\fR function should beused to actually display the warnings message. This is because they canmake use of the feature that allows warnings to be escalated into fatalerrors. So in this case.PP.Vb 4\&    use MyMod::Abc;\&    use warnings FATAL => \*(AqMyMod::Abc\*(Aq;\&    ...\&    MyMod::Abc::open(\*(Aq../fred.txt\*(Aq);.Ve.PPthe \f(CW\*(C`warnings::warnif\*(C'\fR function will detect this and die afterdisplaying the warning message..PPThe three warnings functions, \f(CW\*(C`warnings::warn\*(C'\fR, \f(CW\*(C`warnings::warnif\*(C'\fRand \f(CW\*(C`warnings::enabled\*(C'\fR can optionally take an object reference in placeof a category name. In this case the functions will use the class nameof the object as the warnings category..PPConsider this example:.PP.Vb 1\&    package Original;\&\&    no warnings;\&    use warnings::register;\&\&    sub new\&    {\&        my $class = shift;\&        bless [], $class;\&    }\&\&    sub check\&    {\&        my $self = shift;\&        my $value = shift;\&\&        if ($value % 2 && warnings::enabled($self))\&          { warnings::warn($self, "Odd numbers are unsafe") }\&    }\&\&    sub doit\&    {\&        my $self = shift;\&        my $value = shift;\&        $self\->check($value);\&        # ...\&    }\&\&    1;\&\&    package Derived;\&\&    use warnings::register;\&    use Original;\&    our @ISA = qw( Original );\&    sub new\&    {\&        my $class = shift;\&        bless [], $class;\&    }\&\&\&    1;.Ve.PPThe code below makes use of both modules, but it only enables warnings from \&\f(CW\*(C`Derived\*(C'\fR..PP.Vb 7\&    use Original;\&    use Derived;\&    use warnings \*(AqDerived\*(Aq;\&    my $a = Original\->new();\&    $a\->doit(1);\&    my $b = Derived\->new();\&    $a\->doit(1);.Ve.PPWhen this code is run only the \f(CW\*(C`Derived\*(C'\fR object, \f(CW$b\fR, will generatea warning..PP.Vb 1\&    Odd numbers are unsafe at main.pl line 7.Ve.PPNotice also that the warning is reported at the line where the object is firstused..SH "SEE ALSO".IX Header "SEE ALSO"warnings, perldiag..SH "AUTHOR".IX Header "AUTHOR"Paul Marquess

⌨️ 快捷键说明

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