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

📄 filter::simple.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings.  \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote.  \*(C+ will.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\.    ds -- \(*W-.    ds PI pi.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch.    ds L" "".    ds R" "".    ds C` "".    ds C' ""'br\}.el\{\.    ds -- \|\(em\|.    ds PI \(*p.    ds L" ``.    ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el       .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD.  Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\.    de IX.    tm Index:\\$1\t\\n%\t"\\$2"...    nr % 0.    rr F.\}.el \{\.    de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear.  Run.  Save yourself.  No user-serviceable parts..    \" fudge factors for nroff and troff.if n \{\.    ds #H 0.    ds #V .8m.    ds #F .3m.    ds #[ \f1.    ds #] \fP.\}.if t \{\.    ds #H ((1u-(\\\\n(.fu%2u))*.13m).    ds #V .6m.    ds #F 0.    ds #[ \&.    ds #] \&.\}.    \" simple accents for nroff and troff.if n \{\.    ds ' \&.    ds ` \&.    ds ^ \&.    ds , \&.    ds ~ ~.    ds /.\}.if t \{\.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u".    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}.    \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E.    \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'.    \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\.    ds : e.    ds 8 ss.    ds o a.    ds d- d\h'-1'\(ga.    ds D- D\h'-1'\(hy.    ds th \o'bp'.    ds Th \o'LP'.    ds ae ae.    ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "Filter::Simple 3".TH Filter::Simple 3 "2007-12-18" "perl v5.10.0" "Perl Programmers Reference Guide".\" For nroff, turn off justification.  Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"Filter::Simple \- Simplified source filtering.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 1\& # in MyFilter.pm:\&\&     package MyFilter;\&\&     use Filter::Simple;\&     \&     FILTER { ... };\&\&     # or just:\&     #\&     # use Filter::Simple sub { ... };\&\& # in user\*(Aqs code:\&\&     use MyFilter;\&\&     # this code is filtered\&\&     no MyFilter;\&\&     # this code is not.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION".Sh "The Problem".IX Subsection "The Problem"Source filtering is an immensely powerful feature of recent versions of Perl.It allows one to extend the language itself (e.g. the Switch module), to simplify the language (e.g. Language::Pythonesque), or to completely recast thelanguage (e.g. Lingua::Romana::Perligata). Effectively, it allows one to usethe full power of Perl as its own, recursively applied, macro language..PPThe excellent Filter::Util::Call module (by Paul Marquess) provides ausable Perl interface to source filtering, but it is often too powerfuland not nearly as simple as it could be..PPTo use the module it is necessary to do the following:.IP "1." 4Download, build, and install the Filter::Util::Call module.(If you have Perl 5.7.1 or later, this is already done for you.).IP "2." 4Set up a module that does a \f(CW\*(C`use Filter::Util::Call\*(C'\fR..IP "3." 4Within that module, create an \f(CW\*(C`import\*(C'\fR subroutine..IP "4." 4Within the \f(CW\*(C`import\*(C'\fR subroutine do a call to \f(CW\*(C`filter_add\*(C'\fR, passingit either a subroutine reference..IP "5." 4Within the subroutine reference, call \f(CW\*(C`filter_read\*(C'\fR or \f(CW\*(C`filter_read_exact\*(C'\fRto \*(L"prime\*(R" \f(CW$_\fR with source code data from the source file that will\&\f(CW\*(C`use\*(C'\fR your module. Check the status value returned to see if anysource code was actually read in..IP "6." 4Process the contents of \f(CW$_\fR to change the source code in the desired manner..IP "7." 4Return the status value..IP "8." 4If the act of unimporting your module (via a \f(CW\*(C`no\*(C'\fR) should cause sourcecode filtering to cease, create an \f(CW\*(C`unimport\*(C'\fR subroutine, and have it call\&\f(CW\*(C`filter_del\*(C'\fR. Make sure that the call to \f(CW\*(C`filter_read\*(C'\fR or\&\f(CW\*(C`filter_read_exact\*(C'\fR in step 5 will not accidentally read past the\&\f(CW\*(C`no\*(C'\fR. Effectively this limits source code filters to line-by-lineoperation, unless the \f(CW\*(C`import\*(C'\fR subroutine does some fancypre-pre-parsing of the source code it's filtering..PPFor example, here is a minimal source code filter in a module named\&\s-1BANG\s0.pm. It simply converts every occurrence of the sequence \f(CW\*(C`BANG\es+BANG\*(C'\fRto the sequence \f(CW\*(C`die \*(AqBANG\*(Aq if $BANG\*(C'\fR in any piece of code following a\&\f(CW\*(C`use BANG;\*(C'\fR statement (until the next \f(CW\*(C`no BANG;\*(C'\fR statement, if any):.PP.Vb 1\&    package BANG;\& \&    use Filter::Util::Call ;\&\&    sub import {\&        filter_add( sub {\&        my $caller = caller;\&        my ($status, $no_seen, $data);\&        while ($status = filter_read()) {\&            if (/^\es*no\es+$caller\es*;\es*?$/) {\&                $no_seen=1;\&                last;\&            }\&            $data .= $_;\&            $_ = "";\&        }\&        $_ = $data;\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g\&            unless $status < 0;\&        $_ .= "no $class;\en" if $no_seen;\&        return 1;\&        })\&    }\&\&    sub unimport {\&        filter_del();\&    }\&\&    1 ;.Ve.PPThis level of sophistication puts filtering out of the reach ofmany programmers..Sh "A Solution".IX Subsection "A Solution"The Filter::Simple module provides a simplified interface toFilter::Util::Call; one that is sufficient for most common cases..PPInstead of the above process, with Filter::Simple the task of setting upa source code filter is reduced to:.IP "1." 4Download and install the Filter::Simple module.(If you have Perl 5.7.1 or later, this is already done for you.).IP "2." 4Set up a module that does a \f(CW\*(C`use Filter::Simple\*(C'\fR and thencalls \f(CW\*(C`FILTER { ... }\*(C'\fR..IP "3." 4Within the anonymous subroutine or block that is passed to\&\f(CW\*(C`FILTER\*(C'\fR, process the contents of \f(CW$_\fR to change the source code inthe desired manner..PPIn other words, the previous example, would become:.PP.Vb 2\&    package BANG;\&    use Filter::Simple;\&    \&    FILTER {\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;\&    };\&\&    1 ;.Ve.PPNote that the source code is passed as a single string, so any regex thatuses \f(CW\*(C`^\*(C'\fR or \f(CW\*(C`$\*(C'\fR to detect line boundaries will need the \f(CW\*(C`/m\*(C'\fR flag..Sh "Disabling or changing <no> behaviour".IX Subsection "Disabling or changing <no> behaviour"By default, the installed filter only filters up to a line consisting of one ofthe three standard source \*(L"terminators\*(R":.PP.Vb 1\&    no ModuleName;  # optional comment.Ve.PPor:.PP.Vb 1\&    _\|_END_\|_.Ve.PPor:.PP.Vb 1\&    _\|_DATA_\|_.Ve.PPbut this can be altered by passing a second argument to \f(CW\*(C`use Filter::Simple\*(C'\fRor \f(CW\*(C`FILTER\*(C'\fR (just remember: there's \fIno\fR comma after the initial block whenyou use \f(CW\*(C`FILTER\*(C'\fR)..PPThat second argument may be either a \f(CW\*(C`qr\*(C'\fR'd regular expression (which is thenused to match the terminator line), or a defined false value (which indicatesthat no terminator line should be looked for), or a reference to a hash(in which case the terminator is the value associated with the key\&\f(CW\*(Aqterminator\*(Aq\fR..PPFor example, to cause the previous filter to filter only up to a line of theform:.PP.Vb 1\&    GNAB esu;.Ve.PPyou would write:.PP.Vb 2\&    package BANG;\&    use Filter::Simple;\&    \&    FILTER {\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;\&    }\&    qr/^\es*GNAB\es+esu\es*;\es*?$/;.Ve.PPor:.PP.Vb 4\&    FILTER {\&        s/BANG\es+BANG/die \*(AqBANG\*(Aq if \e$BANG/g;\&    }\&    { terminator => qr/^\es*GNAB\es+esu\es*;\es*?$/ };.Ve.PPand to prevent the filter's being turned off in any way:.PP.Vb 2\&    package BANG;\&    use Filter::Simple;\&    

⌨️ 快捷键说明

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