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

📄 table.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
  merge => "1"and merge "a" to the value:  $table->set(  merge => '1');  $table->merge(merge => 'a');  $val = $table->get('merge');Result:  $val == "1, a";=item *Start with a multivalued pair:  merge => "1"  merge => "2"and merge "a" to the first value;  $table->set(  merge => '1');  $table->add(  merge => '2');  $table->merge(merge => 'a');  @val = $table->get('merge');Result:  $val[0] == "1, a";  $val[1] == "2";Only the first value for the same key is affected.=item *Have no entry and merge "a";  $table->merge(miss => 'a');  $val = $table->get('miss');Result:  $val == "a";=back=head2 C<overlap>For each key/value pair in C<$table_b>, add the data toC<$table_a>. The definition of C<$flags> explains how C<$flags> definethe overlapping method.  $table_a->overlap($table_b, $flags);=over 4=item obj: C<$table_a>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to add the data to.=item arg1: C<$table_b>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to iterate over, adding its data to table C<$table_a>=item arg2: C<$flags> ( integer )How to add the table to table C<$table_a>.When C<$flags> == C<APR::Const::OVERLAP_TABLES_SET>, if another elementalready exists with the same key, this will over-write the old data.When C<$flags> == C<APR::Const::OVERLAP_TABLES_MERGE>, the key/value pairfrom C<$table_b> is added, regardless of whether there is anotherelement with the same key in C<$table_a>.=item ret: no return value=item since: 2.0.00=backAccess the constants via:  use APR::Const -compile qw(:table);or an explicit:  use APR::Const -compile qw(OVERLAP_TABLES_SET OVERLAP_TABLES_MERGE);This function is highly optimized, and uses less memory and CPU cyclesthan a function that just loops through table C<$table_b> callingother functions.Conceptually, C<overlap()> does this:  apr_array_header_t *barr = apr_table_elts(b);  apr_table_entry_t *belt = (apr_table_entry_t *)barr-E<gt>elts;  int i;    for (i = 0; i < barr->nelts; ++i) {      if (flags & APR_OVERLAP_TABLES_MERGE) {          apr_table_mergen(a, belt[i].key, belt[i].val);      }      else {          apr_table_setn(a, belt[i].key, belt[i].val);      }  }Except that it is more efficient (less space and cpu-time) especiallywhen C<$table_b> has many elements.Notice the assumptions on the keys and values in C<$table_b> -- theymust be in an ancestor of C<$table_a>'s pool.  In practice C<$table_b>and C<$table_a> are usually from the same pool.Examples:=over=item * C<APR::Const::OVERLAP_TABLES_SET>Start with table C<$base>:  foo => "one"  foo => "two"  bar => "beer"and table C<$add>:  foo => "three"which is done by:  use APR::Const    -compile => ':table';  my $base = APR::Table::make($r->pool, TABLE_SIZE);  my $add  = APR::Table::make($r->pool, TABLE_SIZE);    $base->set(bar => 'beer');  $base->set(foo => 'one');  $base->add(foo => 'two');    $add->set(foo => 'three');Now overlap using C<APR::Const::OVERLAP_TABLES_SET>:  $base->overlap($add, APR::Const::OVERLAP_TABLES_SET);Now table C<$add> is unmodified and table C<$base> contains:  foo => "three"  bar => "beer"The value from table C<add> has overwritten all previous values forthe same key both had (I<foo>).  This is the same as doingC<L<overlay()|/C_overlay_>> followed by C<L<compress()|/C_compress_>>with C<APR::Const::OVERLAP_TABLES_SET>.=item * C<APR::Const::OVERLAP_TABLES_MERGE>Start with table C<$base>:  foo => "one"  foo => "two"and table C<$add>:  foo => "three"  bar => "beer"which is done by:  use APR::Const    -compile => ':table';  my $base = APR::Table::make($r->pool, TABLE_SIZE);  my $add  = APR::Table::make($r->pool, TABLE_SIZE);    $base->set(foo => 'one');  $base->add(foo => 'two');    $add->set(foo => 'three');  $add->set(bar => 'beer');Now overlap using C<APR::Const::OVERLAP_TABLES_MERGE>:  $base->overlap($add, APR::Const::OVERLAP_TABLES_MERGE);Now table C<$add> is unmodified and table C<$base> contains:  foo => "one, two, three"  bar => "beer"Values from both tables for the same key were merged into onevalue. This is the same as doing C<L<overlay()|/C_overlay_>> followedby C<L<compress()|/C_compress_>> with C<APR::Const::OVERLAP_TABLES_MERGE>.=back=head2 C<overlay>Merge two tables into one new table. The resulting table may have morethan one value for the same key.  $table = $table_base->overlay($table_overlay, $p);=over 4=item obj: C<$table_base>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to add at the end of the new table.=item arg1: C<$table_overlay>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The first table to put in the new table.=item arg2: C<$p>( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )The pool to use for the new table.=item ret: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )A new table containing all of the data from the two passed in.=item since: 2.0.00=backExamples:=over=item *Start with table C<$base>:  foo => "one"  foo => "two"  bar => "beer"and table C<$add>:  foo => "three"which is done by:  use APR::Const    -compile => ':table';  my $base = APR::Table::make($r->pool, TABLE_SIZE);  my $add  = APR::Table::make($r->pool, TABLE_SIZE);    $base->set(bar => 'beer');  $base->set(foo => 'one');  $base->add(foo => 'two');    $add->set(foo => 'three');Now overlay using C<APR::Const::OVERLAP_TABLES_SET>:  my $overlay = $base->overlay($add, APR::Const::OVERLAP_TABLES_SET);That resulted in a new table C<$overlay> (tables C<add> and C<$base>are unmodified) which contains:  foo => "one"  foo => "two"  foo => "three"  bar => "beer"=back=head2 C<set>Add a key/value pair to a table, if another element already existswith the same key, this will over-write the old data.  $table->set($key, $val);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to add the data to.=item arg1: C<$key> ( string )The key to use.=item arg2: C<$val> ( string )The value to add.=item ret: no return value=item since: 2.0.00=backWhen adding data, this function makes a copy of both the key and thevalue.=head2 C<unset>Remove data from the table.  $table->unset($key);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to remove data from.=item arg1: C<$key> ( string )The key of the data being removed.=item ret: no return value=item since: 2.0.00=back=head1 TIE InterfaceC<APR::Table> also implements a tied interface, so you can work with theC<$table> object as a hash reference.The following tied-hash function are supported: C<FETCH>, C<STORE>,C<DELETE>, C<CLEAR>, C<EXISTS>, C<FIRSTKEY>, C<NEXTKEY> andC<DESTROY>.Note regarding the use of C<values()>. C<APR::Table> can hold morethan one key-value pair sharing the same key, so when using a tablethrough the tied interface, the first entry found with the right keywill be used, completely disregarding possible other entries with thesame key.  With Perl 5.8.0 and higher C<values()> will correctly listvalues the corresponding to the list generated by C<keys()>. Thatdoesn't work with Perl 5.6. Therefore to portably iterate over thekey-value pairs, use C<each()> (which fully supports multivaluedkeys), or C<APR::Table::do>.=head2 C<EXISTS>  $ret = $table->EXISTS($key);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )=item arg1: C<$key> ( string )=item ret: C<$ret> ( integer )true or false=item since: 2.0.00=back=head2 C<CLEAR>  $table->CLEAR();=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )=item ret: no return value=item since: 2.0.00=back=head2 C<STORE>  $table->STORE($key, $val);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )=item arg1: C<$key> ( string )=item arg2: C<$val> ( string )=item ret: no return value=item since: 2.0.00=back=head2 C<DELETE>  $table->DELETE($key);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )=item arg1: C<$key> ( string )=item ret: no return value=item since: 2.0.00=back=head2 C<FETCH>  $ret = $table->FETCH($key);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )=item arg1: C<$key> ( string )=item ret: C<$ret> ( string )=item since: 2.0.00=backWhen iterating through the table's entries with C<each()>, C<FETCH>will return the current value of a multivalued key.  For example:  $table->add("a" => 1);  $table->add("b" => 2);  $table->add("a" => 3);    ($k, $v) = each %$table; # (a, 1)  print $table->{a};       # prints 1    ($k, $v) = each %$table; # (b, 2)  print $table->{a};       # prints 1    ($k, $v) = each %$table; # (a, 3)  print $table->{a};       # prints 3 !!!    ($k, $v) = each %$table; # (undef, undef)  print $table->{a};       # prints 1=head1 See AlsoL<mod_perl 2.0 documentation|docs::2.0::index>.=head1 Copyrightmod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0.=head1 AuthorsL<The mod_perl development team and numerouscontributors|about::contributors::people>.=cut

⌨️ 快捷键说明

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