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

📄 dumper.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 3 页
字号:
    }    elsif ($realtype eq 'CODE') {      if ($s->{deparse}) {	require B::Deparse;	my $sub =  'sub ' . (B::Deparse->new)->coderef2text($val);	$pad    =  $s->{sep} . $s->{pad} . $s->{apad} . $s->{xpad} x ($s->{level} - 1);	$sub    =~ s/\n/$pad/gse;	$out   .=  $sub;      } else {        $out .= 'sub { "DUMMY" }';        carp "Encountered CODE ref, using dummy placeholder" if $s->{purity};      }    }    else {      croak "Can\'t handle $realtype type.";    }        if ($realpack) { # we have a blessed ref      $out .= ', ' . _quote($realpack) . ' )';      $out .= '->' . $s->{toaster} . '()'  if $s->{toaster} ne '';      $s->{apad} = $blesspad;    }    $s->{level}--;  }  else {                                 # simple scalar    my $ref = \$_[1];    # first, catalog the scalar    if ($name ne '') {      $id = format_refaddr($ref);      if (exists $s->{seen}{$id}) {        if ($s->{seen}{$id}[2]) {	  $out = $s->{seen}{$id}[0];	  #warn "[<$out]\n";	  return "\${$out}";	}      }      else {	#warn "[>\\$name]\n";	$s->{seen}{$id} = ["\\$name", $ref];      }    }    if (ref($ref) eq 'GLOB' or "$ref" =~ /=GLOB\([^()]+\)$/) {  # glob      my $name = substr($val, 1);      if ($name =~ /^[A-Za-z_][\w:]*$/) {	$name =~ s/^main::/::/;	$sname = $name;      }      else {	$sname = $s->_dump($name, "");	$sname = '{' . $sname . '}';      }      if ($s->{purity}) {	my $k;	local ($s->{level}) = 0;	for $k (qw(SCALAR ARRAY HASH)) {	  my $gval = *$val{$k};	  next unless defined $gval;	  next if $k eq "SCALAR" && ! defined $$gval;  # always there	  # _dump can push into @post, so we hold our place using $postlen	  my $postlen = scalar @post;	  $post[$postlen] = "\*$sname = ";	  local ($s->{apad}) = " " x length($post[$postlen]) if $s->{indent} >= 2;	  $post[$postlen] .= $s->_dump($gval, "\*$sname\{$k\}");	}      }      $out .= '*' . $sname;    }    elsif (!defined($val)) {      $out .= "undef";    }    elsif ($val =~ /^(?:0|-?[1-9]\d{0,8})\z/) { # safe decimal number      $out .= $val;    }    else {				 # string      if ($s->{useqq} or $val =~ tr/\0-\377//c) {        # Fall back to qq if there's Unicode	$out .= qquote($val, $s->{useqq});      }      else {        $out .= _quote($val);      }    }  }  if ($id) {    # if we made it this far, $id was added to seen list at current    # level, so remove it to get deep copies    if ($s->{deepcopy}) {      delete($s->{seen}{$id});    }    elsif ($name) {      $s->{seen}{$id}[2] = 1;    }  }  return $out;}  ## non-OO style of earlier version#sub Dumper {  return Data::Dumper->Dump([@_]);}# compat stubsub DumperX {  return Data::Dumper->Dumpxs([@_], []);}sub Dumpf { return Data::Dumper->Dump(@_) }sub Dumpp { print Data::Dumper->Dump(@_) }## reset the "seen" cache #sub Reset {  my($s) = shift;  $s->{seen} = {};  return $s;}sub Indent {  my($s, $v) = @_;  if (defined($v)) {    if ($v == 0) {      $s->{xpad} = "";      $s->{sep} = "";    }    else {      $s->{xpad} = "  ";      $s->{sep} = "\n";    }    $s->{indent} = $v;    return $s;  }  else {    return $s->{indent};  }}sub Pair {    my($s, $v) = @_;    defined($v) ? (($s->{pair} = $v), return $s) : $s->{pair};}sub Pad {  my($s, $v) = @_;  defined($v) ? (($s->{pad} = $v), return $s) : $s->{pad};}sub Varname {  my($s, $v) = @_;  defined($v) ? (($s->{varname} = $v), return $s) : $s->{varname};}sub Purity {  my($s, $v) = @_;  defined($v) ? (($s->{purity} = $v), return $s) : $s->{purity};}sub Useqq {  my($s, $v) = @_;  defined($v) ? (($s->{useqq} = $v), return $s) : $s->{useqq};}sub Terse {  my($s, $v) = @_;  defined($v) ? (($s->{terse} = $v), return $s) : $s->{terse};}sub Freezer {  my($s, $v) = @_;  defined($v) ? (($s->{freezer} = $v), return $s) : $s->{freezer};}sub Toaster {  my($s, $v) = @_;  defined($v) ? (($s->{toaster} = $v), return $s) : $s->{toaster};}sub Deepcopy {  my($s, $v) = @_;  defined($v) ? (($s->{deepcopy} = $v), return $s) : $s->{deepcopy};}sub Quotekeys {  my($s, $v) = @_;  defined($v) ? (($s->{quotekeys} = $v), return $s) : $s->{quotekeys};}sub Bless {  my($s, $v) = @_;  defined($v) ? (($s->{'bless'} = $v), return $s) : $s->{'bless'};}sub Maxdepth {  my($s, $v) = @_;  defined($v) ? (($s->{'maxdepth'} = $v), return $s) : $s->{'maxdepth'};}sub Useperl {  my($s, $v) = @_;  defined($v) ? (($s->{'useperl'} = $v), return $s) : $s->{'useperl'};}sub Sortkeys {  my($s, $v) = @_;  defined($v) ? (($s->{'sortkeys'} = $v), return $s) : $s->{'sortkeys'};}sub Deparse {  my($s, $v) = @_;  defined($v) ? (($s->{'deparse'} = $v), return $s) : $s->{'deparse'};}# used by qquote belowmy %esc = (      "\a" => "\\a",    "\b" => "\\b",    "\t" => "\\t",    "\n" => "\\n",    "\f" => "\\f",    "\r" => "\\r",    "\e" => "\\e",);# put a string value in double quotessub qquote {  local($_) = shift;  s/([\\\"\@\$])/\\$1/g;  my $bytes; { use bytes; $bytes = length }  s/([^\x00-\x7f])/'\x{'.sprintf("%x",ord($1)).'}'/ge if $bytes > length;  return qq("$_") unless     /[^ !"\#\$%&'()*+,\-.\/0-9:;<=>?\@A-Z[\\\]^_`a-z{|}~]/;  # fast exit  my $high = shift || "";  s/([\a\b\t\n\f\r\e])/$esc{$1}/g;  if (ord('^')==94)  { # ascii    # no need for 3 digits in escape for these    s/([\0-\037])(?!\d)/'\\'.sprintf('%o',ord($1))/eg;    s/([\0-\037\177])/'\\'.sprintf('%03o',ord($1))/eg;    # all but last branch below not supported --BEHAVIOR SUBJECT TO CHANGE--    if ($high eq "iso8859") {      s/([\200-\240])/'\\'.sprintf('%o',ord($1))/eg;    } elsif ($high eq "utf8") {#     use utf8;#     $str =~ s/([^\040-\176])/sprintf "\\x{%04x}", ord($1)/ge;    } elsif ($high eq "8bit") {        # leave it as it is    } else {      s/([\200-\377])/'\\'.sprintf('%03o',ord($1))/eg;      s/([^\040-\176])/sprintf "\\x{%04x}", ord($1)/ge;    }  }  else { # ebcdic      s{([^ !"\#\$%&'()*+,\-.\/0-9:;<=>?\@A-Z[\\\]^_`a-z{|}~])(?!\d)}       {my $v = ord($1); '\\'.sprintf(($v <= 037 ? '%o' : '%03o'), $v)}eg;      s{([^ !"\#\$%&'()*+,\-.\/0-9:;<=>?\@A-Z[\\\]^_`a-z{|}~])}       {'\\'.sprintf('%03o',ord($1))}eg;  }  return qq("$_");}# helper sub to sort hash keys in Perl < 5.8.0 where we don't have# access to sortsv() from XSsub _sortkeys { [ sort keys %{$_[0]} ] }1;__END__=head1 NAMEData::Dumper - stringified perl data structures, suitable for both printing and C<eval>=head1 SYNOPSIS    use Data::Dumper;    # simple procedural interface    print Dumper($foo, $bar);    # extended usage with names    print Data::Dumper->Dump([$foo, $bar], [qw(foo *ary)]);    # configuration variables    {      local $Data::Dumper::Purity = 1;      eval Data::Dumper->Dump([$foo, $bar], [qw(foo *ary)]);    }    # OO usage    $d = Data::Dumper->new([$foo, $bar], [qw(foo *ary)]);       ...    print $d->Dump;       ...    $d->Purity(1)->Terse(1)->Deepcopy(1);    eval $d->Dump;=head1 DESCRIPTIONGiven a list of scalars or reference variables, writes out their contents inperl syntax. The references can also be objects.  The contents of eachvariable is output in a single Perl statement.  Handles self-referentialstructures correctly.The return value can be C<eval>ed to get back an identical copy of theoriginal reference structure.Any references that are the same as one of those passed in will be namedC<$VAR>I<n> (where I<n> is a numeric suffix), and other duplicate referencesto substructures within C<$VAR>I<n> will be appropriately labeled using arrownotation.  You can specify names for individual values to be dumped if youuse the C<Dump()> method, or you can change the default C<$VAR> prefix tosomething else.  See C<$Data::Dumper::Varname> and C<$Data::Dumper::Terse>below.The default output of self-referential structures can be C<eval>ed, but thenested references to C<$VAR>I<n> will be undefined, since a recursivestructure cannot be constructed using one Perl statement.  You should set theC<Purity> flag to 1 to get additional statements that will correctly fill inthese references.  Moreover, if C<eval>ed when strictures are in effect,you need to ensure that any variables it accesses are previously declared.In the extended usage form, the references to be dumped can be givenuser-specified names.  If a name begins with a C<*>, the output will describe the dereferenced type of the supplied reference for hashes andarrays, and coderefs.  Output of names will be avoided where possible ifthe C<Terse> flag is set.In many cases, methods that are used to set the internal state of theobject will return the object itself, so method calls can be convenientlychained together.Several styles of output are possible, all controlled by settingthe C<Indent> flag.  See L<Configuration Variables or Methods> below for details.=head2 Methods=over 4=item I<PACKAGE>->new(I<ARRAYREF [>, I<ARRAYREF]>)Returns a newly created C<Data::Dumper> object.  The first argument is ananonymous array of values to be dumped.  The optional second argument is ananonymous array of names for the values.  The names need not have a leadingC<$> sign, and must be comprised of alphanumeric characters.  You can begina name with a C<*> to specify that the dereferenced type must be dumpedinstead of the reference itself, for ARRAY and HASH references.The prefix specified by C<$Data::Dumper::Varname> will be used with anumeric suffix if the name for a value is undefined.Data::Dumper will catalog all references encountered while dumping thevalues. Cross-references (in the form of names of substructures in perlsyntax) will be inserted at all possible points, preserving any structuralinterdependencies in the original set of values.  Structure traversal isdepth-first,  and proceeds in order from the first supplied value tothe last.=item I<$OBJ>->Dump  I<or>  I<PACKAGE>->Dump(I<ARRAYREF [>, I<ARRAYREF]>)Returns the stringified form of the values stored in the object (preservingthe order in which they were supplied to C<new>), subject to theconfiguration options below.  In a list context, it returns a listof strings corresponding to the supplied values.The second form, for convenience, simply calls the C<new> method on itsarguments before dumping the object immediately.=item I<$OBJ>->Seen(I<[HASHREF]>)Queries or adds to the internal table of already encountered references.You must use C<Reset> to explicitly clear the table if needed.  Suchreferences are not dumped; instead, their names are inserted wherever theyare encountered subsequently.  This is useful especially for properlydumping subroutine references.Expects an anonymous hash of name => value pairs.  Same rules apply for namesas in C<new>.  If no argument is supplied, will return the "seen" list ofname => value pairs, in a list context.  Otherwise, returns the objectitself.=item I<$OBJ>->Values(I<[ARRAYREF]>)Queries or replaces the internal array of values that will be dumped.When called without arguments, returns the values.  Otherwise, returns theobject itself.=item I<$OBJ>->Names(I<[ARRAYREF]>)Queries or replaces the internal array of user supplied names for the valuesthat will be dumped.  When called without arguments, returns the names.Otherwise, returns the object itself.=item I<$OBJ>->ResetClears the internal table of "seen" references and returns the objectitself.=back=head2 Functions=over 4=item Dumper(I<LIST>)Returns the stringified form of the values in the list, subject to theconfiguration options below.  The values will be named C<$VAR>I<n> in theoutput, where I<n> is a numeric suffix.  Will return a list of stringsin a list context.=back=head2 Configuration Variables or MethodsSeveral configuration variables can be used to control the kind of outputgenerated when using the procedural interface.  These variables are usuallyC<local>ized in a block so that other parts of the code are not affected bythe change.  

⌨️ 快捷键说明

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