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

📄 dbm_filter.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
字号:
.\" 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 "DBM_Filter 3".TH DBM_Filter 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"DBM_Filter \-\- Filter DBM keys/values.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 2\&    use DBM_Filter ;\&    use SDBM_File; # or DB_File, or GDBM_File, or NDBM_File, or ODBM_File\&\&    $db = tie %hash, ...\&\&    $db\->Filter_Push(Fetch => sub {...},\&                     Store => sub {...});\&\&    $db\->Filter_Push(\*(Aqmy_filter1\*(Aq);\&    $db\->Filter_Push(\*(Aqmy_filter2\*(Aq, params...);\&\&    $db\->Filter_Key_Push(...) ;\&    $db\->Filter_Value_Push(...) ;\&\&    $db\->Filter_Pop();\&    $db\->Filtered();\&\&    package DBM_Filter::my_filter1;\&    \&    sub Store { ... }\&    sub Fetch { ... }\&\&    1;\&\&    package DBM_Filter::my_filter2;\&\&    sub Filter\&    {\&        my @opts = @_;\&        ...\&        return (\&            sub Store { ... },\&            sub Fetch { ... } );\&    }\&\&    1;.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"This module provides an interface that allows filters to be appliedto tied Hashes associated with \s-1DBM\s0 files. It builds on the \s-1DBM\s0 Filterhooks that are present in all the *DB*_File modules included with thestandard Perl source distribution from version 5.6.1 onwards. In additionto the *DB*_File modules distributed with Perl, the BerkeleyDB module,available on \s-1CPAN\s0, supports the \s-1DBM\s0 Filter hooks. See perldbmfilterfor more details on the \s-1DBM\s0 Filter hooks..SH "What is a DBM Filter?".IX Header "What is a DBM Filter?"A \s-1DBM\s0 Filter allows the keys and/or values in a tied hash to be modifiedby some user-defined code just before it is written to the \s-1DBM\s0 file andjust after it is read back from the \s-1DBM\s0 file. For example, this snippetof code.PP.Vb 1\&    $some_hash{"abc"} = 42;.Ve.PPcould potentially trigger two filters, one for the writing of the key\&\*(L"abc\*(R" and another for writing the value 42.  Similarly, this snippet.PP.Vb 1\&    my ($key, $value) = each %some_hash.Ve.PPwill trigger two filters, one for the reading of the key and one forthe reading of the value..PPLike the existing \s-1DBM\s0 Filter functionality, this module arranges for the\&\f(CW$_\fR variable to be populated with the key or value that a filter willcheck. This usually means that most \s-1DBM\s0 filters tend to be very short..Sh "So what's new?".IX Subsection "So what's new?"The main enhancements over the standard \s-1DBM\s0 Filter hooks are:.IP "\(bu" 4A cleaner interface..IP "\(bu" 4The ability to easily apply multiple filters to a single \s-1DBM\s0 file..IP "\(bu" 4The ability to create \*(L"canned\*(R" filters. These allow commonly used filtersto be packaged into a stand-alone module..SH "METHODS".IX Header "METHODS"This module will arrange for the following methods to be available viathe object returned from the \f(CW\*(C`tie\*(C'\fR call..ie n .Sh "$db\fP\->\fIFilter_Push()".el .Sh "\f(CW$db\fP\->\fIFilter_Push()\fP".IX Subsection "$db->Filter_Push()".ie n .Sh "$db\fP\->\fIFilter_Key_Push()".el .Sh "\f(CW$db\fP\->\fIFilter_Key_Push()\fP".IX Subsection "$db->Filter_Key_Push()".ie n .Sh "$db\fP\->\fIFilter_Value_Push()".el .Sh "\f(CW$db\fP\->\fIFilter_Value_Push()\fP".IX Subsection "$db->Filter_Value_Push()"Add a filter to filter stack for the database, \f(CW$db\fR. The three formatsvary only in whether they apply to the \s-1DBM\s0 key, the \s-1DBM\s0 value or both..IP "Filter_Push" 5.IX Item "Filter_Push"The filter is applied to \fIboth\fR keys and values..IP "Filter_Key_Push" 5.IX Item "Filter_Key_Push"The filter is applied to the key \fIonly\fR..IP "Filter_Value_Push" 5.IX Item "Filter_Value_Push"The filter is applied to the value \fIonly\fR..ie n .Sh "$db\fP\->\fIFilter_Pop()".el .Sh "\f(CW$db\fP\->\fIFilter_Pop()\fP".IX Subsection "$db->Filter_Pop()"Removes the last filter that was applied to the \s-1DBM\s0 file associated with\&\f(CW$db\fR, if present..ie n .Sh "$db\fP\->\fIFiltered()".el .Sh "\f(CW$db\fP\->\fIFiltered()\fP".IX Subsection "$db->Filtered()"Returns \s-1TRUE\s0 if there are any filters applied to the \s-1DBM\s0 associatedwith \f(CW$db\fR.  Otherwise returns \s-1FALSE\s0..SH "Writing a Filter".IX Header "Writing a Filter"Filters can be created in two main ways.Sh "Immediate Filters".IX Subsection "Immediate Filters"An immediate filter allows you to specify the filter code to be usedat the point where the filter is applied to a dbm. In this mode theFilter_*_Push methods expects to receive exactly two parameters..PP.Vb 3\&    my $db = tie %hash, \*(AqSDBM_File\*(Aq, ...\&    $db\->Filter_Push( Store => sub { },\&                      Fetch => sub { });.Ve.PPThe code reference associated with \f(CW\*(C`Store\*(C'\fR will be called before anykey/value is written to the database and the code reference associatedwith \f(CW\*(C`Fetch\*(C'\fR will be called after any key/value is read from thedatabase..PPFor example, here is a sample filter that adds a trailing \s-1NULL\s0 characterto all strings before they are written to the \s-1DBM\s0 file, and removes thetrailing \s-1NULL\s0 when they are read from the \s-1DBM\s0 file.PP.Vb 3\&    my $db = tie %hash, \*(AqSDBM_File\*(Aq, ...\&    $db\->Filter_Push( Store => sub { $_ .= "\ex00" ; },\&                      Fetch => sub { s/\ex00$// ;    });.Ve.PPPoints to note:.IP "1." 5Both the Store and Fetch filters manipulate \f(CW$_\fR..Sh "Canned Filters".IX Subsection "Canned Filters"Immediate filters are useful for one-off situations. For more genericproblems it can be useful to package the filter up in its own module..PPThe usage is for a canned filter is:.PP.Vb 1\&    $db\->Filter_Push("name", params).Ve.PPwhere.ie n .IP """name""" 5.el .IP "``name''" 5.IX Item "name"is the name of the module to load. If the string specified does notcontain the package separator characters \*(L"::\*(R", it is assumed to refer tothe full module name \*(L"DBM_Filter::name\*(R". This means that the full namesfor canned filters, \*(L"null\*(R" and \*(L"utf8\*(R", included with this module are:.Sp.Vb 2\&    DBM_Filter::null\&    DBM_Filter::utf8.Ve.IP "params" 5.IX Item "params"any optional parameters that need to be sent to the filter. See theencode filter for an example of a module that uses parameters..PPThe module that implements the canned filter can take one of twoforms. Here is a template for the first.PP.Vb 1\&    package DBM_Filter::null ;\&\&    use strict;\&    use warnings;\&\&    sub Store \&    {\&        # store code here    \&    }\&\&    sub Fetch\&    {\&        # fetch code here\&    }\&\&    1;.Ve.PPNotes:.IP "1." 5The package name uses the \f(CW\*(C`DBM_Filter::\*(C'\fR prefix..IP "2." 5The module \fImust\fR have both a Store and a Fetch method. If only one ispresent, or neither are present, a fatal error will be thrown..PPThe second form allows the filter to hold state information using aclosure, thus:.PP.Vb 1\&    package DBM_Filter::encoding ;\&\&    use strict;\&    use warnings;\&\&    sub Filter\&    {\&        my @params = @_ ;\&\&        ...\&        return {\&            Store   => sub { $_ = $encoding\->encode($_) },\&            Fetch   => sub { $_ = $encoding\->decode($_) }\&            } ;\&    }\&\&    1;.Ve.PPIn this instance the \*(L"Store\*(R" and \*(L"Fetch\*(R" methods are encapsulated inside a\&\*(L"Filter\*(R" method..SH "Filters Included".IX Header "Filters Included"A number of canned filers are provided with this module. They cover anumber of the main areas that filters are needed when interfacing with\&\s-1DBM\s0 files. They also act as templates for your own filters..PPThe filter included are:.IP "\(bu" 5utf8.SpThis module will ensure that all data written to the \s-1DBM\s0 will be encodedin \s-1UTF\-8\s0..SpThis module needs the Encode module..IP "\(bu" 5encode.SpAllows you to choose the character encoding will be store in the \s-1DBM\s0 file..IP "\(bu" 5compress.SpThis filter will compress all data before it is written to the databaseand uncompressed it on reading..SpThis module needs Compress::Zlib..IP "\(bu" 5int32.SpThis module is used when interoperating with a C/\*(C+ application thatuses a C int as either the key and/or value in the \s-1DBM\s0 file..IP "\(bu" 5null.SpThis module ensures that all data written to the \s-1DBM\s0 file is nullterminated. This is useful when you have a perl script that needsto interoperate with a \s-1DBM\s0 file that a C program also uses. A fairlycommon issue is for the C application to include the terminating nullin a string when it writes to the \s-1DBM\s0 file. This filter will ensure thatall data written to the \s-1DBM\s0 file can be read by the C application..SH "NOTES".IX Header "NOTES".Sh "Maintain Round Trip Integrity".IX Subsection "Maintain Round Trip Integrity"When writing a \s-1DBM\s0 filter it is \fIvery\fR important to ensure that it ispossible to retrieve all data that you have written when the \s-1DBM\s0 filteris in place. In practice, this means that whatever transformation isapplied to the data in the Store method, the \fIexact\fR inverse operationshould be applied in the Fetch method..PPIf you don't provide an exact inverse transformation, you will find thatcode like this will not behave as you expect..PP.Vb 4\&     while (my ($k, $v) = each %hash)\&     {\&         ...\&     }.Ve.PPDepending on the transformation, you will find that one or more of thefollowing will happen.IP "1." 5The loop will never terminate..IP "2." 5Too few records will be retrieved..IP "3." 5Too many will be retrieved..IP "4." 5The loop will do the right thing for a while, but it will unexpectedly fail..Sh "Don't mix filtered & non-filtered data in the same database file.".IX Subsection "Don't mix filtered & non-filtered data in the same database file."This is just a restatement of the previous section. Unless you arecompletely certain you know what you are doing, avoid mixing filtered &non-filtered data..SH "EXAMPLE".IX Header "EXAMPLE"Say you need to interoperate with a legacy C application that storeskeys as C ints and the values and null terminated \s-1UTF\-8\s0 strings. Hereis how you would set that up.PP.Vb 1\&    my $db = tie %hash, \*(AqSDBM_File\*(Aq, ...\&\&    $db\->Filter_Key_Push(\*(Aqint32\*(Aq) ;\&\&    $db\->Filter_Value_Push(\*(Aqutf8\*(Aq);\&    $db\->Filter_Value_Push(\*(Aqnull\*(Aq);.Ve.SH "SEE ALSO".IX Header "SEE ALSO"<DB_File>,  GDBM_File, NDBM_File, ODBM_File, SDBM_File, perldbmfilter.SH "AUTHOR".IX Header "AUTHOR"Paul Marquess <pmqs@cpan.org>

⌨️ 快捷键说明

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