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

📄 table.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
# # /*#  * *********** WARNING **************#  * This file generated by ModPerl::WrapXS/0.01#  * Any changes made here will be lost#  * ***********************************#  * 01: lib/ModPerl/Code.pm:708#  * 02: lib/ModPerl/WrapXS.pm:624#  * 03: lib/ModPerl/WrapXS.pm:1173#  * 04: Makefile.PL:423#  * 05: Makefile.PL:325#  * 06: Makefile.PL:56#  */# package APR::Table;use strict;use warnings FATAL => 'all';use APR ();use APR::XSLoader ();our $VERSION = '0.009000';APR::XSLoader::load __PACKAGE__;1;__END__=head1 NAMEAPR::Table - Perl API for manipulating APR opaque string-content tables=head1 Synopsis  use APR::Table ();    $table = APR::Table::make($pool, $nelts);  $table_copy = $table->copy($pool);    $table->clear();    $table->set($key => $val);  $table->unset($key);  $table->add($key, $val);    $val = $table->get($key);  @val = $table->get($key);    $table->merge($key => $val);    use APR::Const -compile qw(:table);  $table_overlay = $table_base->overlay($table_overlay, $pool);  $table_overlay->compress(APR::Const::OVERLAP_TABLES_MERGE);    $table_a->overlap($table_b, APR::Const::OVERLAP_TABLES_SET);    $table->do(sub {print "key $_[0], value $_[1]\n"}, @valid_keys);    #Tied Interface  $value = $table->{$key};  $table->{$key} = $value;  print "got it" if exists $table->{$key};    foreach my $key (keys %{$table}) {      print "$key = $table->{$key}\n";  }=head1 DescriptionC<APR::Table> allows its users to manipulate opaque string-contenttables.On the C level the "opaque string-content" means: you can put in'\0'-terminated strings and whatever you put in your get out.On the Perl level that means that we convert scalars into strings andstore those strings. Any special information that was in the Perlscalar is not stored. So for example if a scalar was marked as utf8,tainted or tied, that information is not stored. When you get the databack as a Perl scalar you get only the string.The table's structure is somewhat similar to the Perl's hashstructure, but allows multiple values for the same key.  An access tothe records stored in the table always requires a key.The key-value pairs are stored in the order they are added.The keys are case-insensitive.However as of the current implementation if more than value for thesame key is requested, the whole table is lineary searched, which isvery inefficient unless the table is very small.C<APR::Table> provides a L<TIE Interface|/TIE_Interface>.See I<apr/include/apr_tables.h> in ASF's I<apr> project for low leveldetails.=head1 APIC<APR::Table> provides the following functions and/or methods:=head2 C<add>Add data to a table, regardless of whether there is another elementwith the same key.  $table->add($key, $val);=over 4=item obj: C<$table> ( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to add 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<clear>Delete all of the elements from a table.  $table->clear();=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to clear.=item ret: no return value=item since: 2.0.00=back=head2 C<compress>Eliminate redundant entries in a table by either overwriting ormerging duplicates:  $table->compress($flags);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to compress.=item arg1: C<$flags>(C<L<APR::Const constant|docs::2.0::api::APR::Const>>)  APR::Const::OVERLAP_TABLES_MERGE -- to merge  APR::Const::OVERLAP_TABLES_SET   -- to overwrite=item ret: no return value=item since: 2.0.00=backConverts multi-valued keys in C<$table> into single-valued keys.  Thisfunction takes duplicate table entries and flattens them into a singleentry.  The flattening behavior is controlled by the (mandatory)C<$flags> argument.When C<$flags> == C<APR::Const::OVERLAP_TABLES_SET>, each key will be set tothe last value seen for that key.  For example, given key/value pairs'foo =E<gt> bar' and 'foo =E<gt> baz', 'foo' would have a final valueof 'baz' after compression -- the 'bar' value would be lost.When C<$flags> == C<APR::Const::OVERLAP_TABLES_MERGE>, multiple values forthe same key are flattened into a comma-separated list.  Givenkey/value pairs 'foo =E<gt> bar' and 'foo =E<gt> baz', 'foo' wouldhave a final value of 'bar, baz' after compression.Access the constants via:  use APR::Const -compile qw(:table);or an explicit:  use APR::Const -compile qw(OVERLAP_TABLES_SET OVERLAP_TABLES_MERGE);C<compress()> combined with C<L<overlay()|/C_overlay_>> does the samething as C<L<overlap()|/C_overlap_>>.Examples:=over=item * C<APR::Const::OVERLAP_TABLES_SET>Start with table C<$table>:  foo => "one"  foo => "two"  foo => "three"  bar => "beer"which is done by:  use APR::Const    -compile => ':table';  my $table = APR::Table::make($r->pool, TABLE_SIZE);    $table->set(bar => 'beer');  $table->set(foo => 'one');  $table->add(foo => 'two');  $table->add(foo => 'three');Now compress it using C<APR::Const::OVERLAP_TABLES_SET>:  $table->compress(APR::Const::OVERLAP_TABLES_SET);Now table C<$table> contains:  foo => "three"  bar => "beer"The value I<three> for the key I<foo>, that was added last, took overthe other values.=item * C<APR::Const::OVERLAP_TABLES_MERGE>Start with table C<$table>:  foo => "one"  foo => "two"  foo => "three"  bar => "beer"as in the previous example, now compress it usingC<APR::Const::OVERLAP_TABLES_MERGE>:  $table->compress(APR::Const::OVERLAP_TABLES_MERGE);Now table C<$table> contains:  foo => "one, two, three"  bar => "beer"All the values for the same key were merged into one value.=back=head2 C<copy>Create a new table and copy another table into it.  $table_copy = $table->copy($p);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to copy.=item arg1: C<$p>( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )The pool to allocate the new table out of.=item ret: C<$table_copy>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )A copy of the table passed in.=item since: 2.0.00=back=head2 C<do>Iterate over all the elements of the table, invoking providedsubroutine for each element.  The subroutine gets passed as argument,a key-value pair.  $table->do(sub {...}, @filter);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to operate on.=item arg1: C<$sub> ( CODE ref/string )A subroutine reference or name to be called on each item in the table.The subroutine can abort the iteration by returning 0 and shouldalways return 1 otherwise.=item opt arg3: C<@filter> ( ARRAY )If passed, only keys matching one of the entries in fC<@filter> will beprocessed.=item ret: no return value=item since: 2.0.00=backExamples:=over=item *This filter simply prints out the key/value pairs and counts how manypairs did it see.  use constant TABLE_SIZE => 20;  our $filter_count;  my $table = APR::Table::make($r->pool, TABLE_SIZE);    # populate the table with ascii data  for (1..TABLE_SIZE) {      $table->set(chr($_+97), $_);  }    $filter_count = 0;  $table->do("my_filter");  print "Counted $filter_count elements";    sub my_filter {      my ($key, $value) = @_;      warn "$key => $value\n";      $filter_count++;      return 1;  }Notice that C<my_filter> always returns 1, ensuring that C<do()> willpass all the key/value pairs.=item *This filter is similar to the one from the previous example, but thistime it decides to abort the filtering after seeing half of the table,by returning 0 when this happens.  sub my_filter {      my ($key, $value) = @_;      $filter_count++;      return $filter_count == int(TABLE_SIZE)/2 ? 0 : 1;  }=back=head2 C<get>Get the value(s) associated with a given key.  After this call, thedata is still in the table.  $val = $table->get($key);  @val = $table->get($key);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to search for the key.=item arg1: C<$key> ( string )The key to search for.=item ret: C<$val> or C<@val>In the scalar context the first matching value returned (the oldest inthe table, if there is more than one value). If nothing matchesC<undef> is returned.In the list context the whole table is traversed and all matchingvalues are returned. An empty list is returned if nothing matches.=item since: 2.0.00=back=head2 C<make>Make a new table.  $table = APR::Table::make($p, $nelts);=over 4=item obj: C<$p>( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )The pool to allocate the pool out of.=item arg1: C<$nelts> ( integer )The number of elements in the initial table. At least 1 or more. If 0is passed APR will still allocate 1.=item ret: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The new table.=item since: 2.0.00=backThis table can only store text data.=head2 C<merge>Add data to a table by merging the value with data that has alreadybeen stored using ", " as a separator:  $table->merge($key, $val);=over 4=item obj: C<$table>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )The table to search for the data.=item arg1: C<$key> ( string )The key to merge data for.=item arg2: C<$val> ( string )The data to add.=item ret: no return value=item since: 2.0.00=backIf the key is not found, then this function acts likeC<L<add()|/C_add_>>.If there is more than one value for the same key, only the first (theoldest) value gets merged.Examples:=over=item *Start with a pair:

⌨️ 快捷键说明

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