📄 yaml.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 "YAML 3".TH YAML 3 "2007-09-27" "perl v5.10.0" "User Contributed Perl Documentation".\" 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"YAML \- YAML Ain't Markup Language (tm).SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 1\& use YAML;\& \& # Load a YAML stream of 3 YAML documents into Perl data structures.\& my ($hashref, $arrayref, $string) = Load(<<\*(Aq...\*(Aq);\& \-\-\-\& name: ingy\& age: old\& weight: heavy\& # I should comment that I also like pink, but don\*(Aqt tell anybody.\& favorite colors:\& \- red\& \- green\& \- blue\& \-\-\-\& \- Clark Evans\& \- Oren Ben\-Kiki\& \- Ingy dA\*~Xt Net\& \-\-\- >\& You probably think YAML stands for "Yet Another Markup Language". It\& ain\*(Aqt! YAML is really a data serialization language. But if you want\& to think of it as a markup, that\*(Aqs OK with me. A lot of people try\& to use XML as a serialization format.\& \& "YAML" is catchy and fun to say. Try it. "YAML, YAML, YAML!!!"\& ...\& \& # Dump the Perl data structures back into YAML.\& print Dump($string, $arrayref, $hashref); \& \& # YAML::Dump is used the same way you\*(Aqd use Data::Dumper::Dumper\& use Data::Dumper;\& print Dumper($string, $arrayref, $hashref);.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"The \s-1YAML\s0.pm module implements a \s-1YAML\s0 Loader and Dumper based on the \s-1YAML\s01.0 specification. <http://www.yaml.org/spec/>.PP\&\s-1YAML\s0 is a generic data serialization language that is optimized forhuman readability. It can be used to express the data structures of mostmodern programming languages. (Including Perl!!!).PPFor information on the \s-1YAML\s0 syntax, please refer to the \s-1YAML\s0specification..SH "WHY YAML IS COOL".IX Header "WHY YAML IS COOL".IP "\s-1YAML\s0 is readable for people." 4.IX Item "YAML is readable for people."It makes clear sense out of complex data structures. You should findthat \s-1YAML\s0 is an exceptional data dumping tool. Structure is shownthrough indentation, \s-1YAML\s0 supports recursive data, and hash keys aresorted by default. In addition, \s-1YAML\s0 supports several styles of scalarformatting for different types of data..IP "\s-1YAML\s0 is editable." 4.IX Item "YAML is editable."\&\s-1YAML\s0 was designed from the ground up to be an excellent syntax forconfiguration files. Almost all programs need configuration files, sowhy invent a new syntax for each one? And why subject users to thecomplexities of \s-1XML\s0 or native Perl code?.IP "\s-1YAML\s0 is multilingual." 4.IX Item "YAML is multilingual."Yes, \s-1YAML\s0 supports Unicode. But I'm actually referring to programminglanguages. \s-1YAML\s0 was designed to meet the serialization needs of Perl,Python, Ruby, Tcl, \s-1PHP\s0, Javascript and Java. It was also designed to beinteroperable between those languages. That means \s-1YAML\s0 serializationsproduced by Perl can be processed by Python..IP "\s-1YAML\s0 is taint safe." 4.IX Item "YAML is taint safe."Using modules like Data::Dumper for serialization is fine as long as youcan be sure that nobody can tamper with your data files ortransmissions. That's because you need to use Perl's \f(CW\*(C`eval()\*(C'\fR built-into deserialize the data. Somebody could add a snippet of Perl to eraseyour files..Sp\&\s-1YAML\s0's parser does not need to eval anything..IP "\s-1YAML\s0 is full featured." 4.IX Item "YAML is full featured."\&\s-1YAML\s0 can accurately serialize all of the common Perl data structures anddeserialize them again without losing data relationships. Although it isnot 100% perfect (no serializer is or can be perfect), it fares as wellas the popular current modules: Data::Dumper, Storable, XML::Dumper andData::Denter..Sp\&\s-1YAML\s0.pm also has the ability to handle code (subroutine) references andtypeglobs. (Still experimental) These features are not found in Perl'sother serialization modules..IP "\s-1YAML\s0 is extensible." 4.IX Item "YAML is extensible."The \s-1YAML\s0 language has been designed to be flexible enough to solve it'sown problems. The markup itself has 3 basic construct which resemblePerl's hash, array and scalar. By default, these map to their Perlequivalents. But each \s-1YAML\s0 node also supports a tagging mechanism (typesystem) which can cause that node to be interpreted in a completelydifferent manner. That's how \s-1YAML\s0 can support object serialization andoddball structures like Perl's typeglob..SH "YAML IMPLEMENTATIONS IN PERL".IX Header "YAML IMPLEMENTATIONS IN PERL"This module, \s-1YAML\s0.pm, is really just the interface module for \s-1YAML\s0modules written in Perl. The basic interface for \s-1YAML\s0 consists of twofunctions: \f(CW\*(C`Dump\*(C'\fR and \f(CW\*(C`Load\*(C'\fR. The real work is done by the modulesYAML::Dumper and YAML::Loader..PPDifferent \s-1YAML\s0 module distributions can be created by subclassing\&\s-1YAML\s0.pm and YAML::Loader and YAML::Dumper. For example, YAML-Simpleconsists of YAML::Simple YAML::Dumper::Simple and YAML::Loader::Simple..PPWhy would there be more than one implementation of \s-1YAML\s0? Well, despite\&\s-1YAML\s0's offering of being a simple data format, \s-1YAML\s0 is actually verydeep and complex. Implementing the entirety of the \s-1YAML\s0 specification isa daunting task..PPFor this reason I am currently working on 3 different \s-1YAML\s0 implementations..IP "\s-1YAML\s0" 4.IX Item "YAML"The main \s-1YAML\s0 distribution will keeping evolving to support the entire\&\s-1YAML\s0 specification in pure Perl. This may not be the fastest or moststable module though. Currently, \s-1YAML\s0.pm has lots of known bugs. It ismostly a great tool for dumping Perl data structures to a readable form..IP "YAML::Lite" 4.IX Item "YAML::Lite"The point of YAML::Lite is to strip \s-1YAML\s0 down to the 90% that peopleuse most and offer that in a small, fast, stable, pure Perl form.YAML::Lite will simply die when it is asked to do something it can't..IP "YAML::Syck" 4.IX Item "YAML::Syck"\&\f(CW\*(C`libsyck\*(C'\fR is the C based \s-1YAML\s0 processing library used by the Rubyprogramming language (and also Python, \s-1PHP\s0 and Pugs). YAML::Syck is thePerl binding to \f(CW\*(C`libsyck\*(C'\fR. It should be very fast, but may haveproblems of its own. It will also require C compilation..Sp\&\s-1NOTE:\s0 Audrey Tang has actually completed this module and it works great and is 10 times faster than \s-1YAML\s0.pm..PPIn the future, there will likely be even more \s-1YAML\s0 modules. Remember,people other than Ingy are allowed to write \s-1YAML\s0 modules!.SH "FUNCTIONAL USAGE".IX Header "FUNCTIONAL USAGE"\&\s-1YAML\s0 is completely \s-1OO\s0 under the hood. Still it exports a few useful toplevel functions so that it is dead simple to use. These functions justdo the \s-1OO\s0 stuff for you. If you want direct access to the \s-1OO\s0 \s-1API\s0 see thedocumentation for YAML::Dumper and YAML::Loader..Sh "Exported Functions".IX Subsection "Exported Functions"The following functions are exported by \s-1YAML\s0.pm by default. The reasonthey are exported is so that \s-1YAML\s0 works much like Data::Dumper. If youdon't want functions to be imported, just use \s-1YAML\s0 with an emptyimport list:.PP.Vb 1\& use YAML ();.Ve.IP "Dump(list\-of\-Perl\-data\-structures)" 4.IX Item "Dump(list-of-Perl-data-structures)"Turn Perl data into \s-1YAML\s0. This function works very much like\&\fIData::Dumper::Dumper()\fR. It takes a list of Perl data strucures anddumps them into a serialized form. It returns a string containing the\&\s-1YAML\s0 stream. The structures can be references or plain scalars..IP "Load(string\-containing\-a\-YAML\-stream)" 4.IX Item "Load(string-containing-a-YAML-stream)"Turn \s-1YAML\s0 into Perl data. This is the opposite of Dump. Just likeStorable's \fIthaw()\fR function or the \fIeval()\fR function in relation toData::Dumper. It parses a string containing a valid \s-1YAML\s0 stream into alist of Perl data structures..Sh "Exportable Functions".IX Subsection "Exportable Functions"These functions are not exported by default but you can request them inan import list like this:.PP.Vb 1\& use YAML qw\*(Aqfreeze thaw Bless\*(Aq;.Ve.IP "\fIfreeze()\fR and \fIthaw()\fR" 4.IX Item "freeze() and thaw()"Aliases to \fIDump()\fR and \fILoad()\fR for Storable fans. This will also allow\&\s-1YAML\s0.pm to be plugged directly into modules like \s-1POE\s0.pm, that use thefreeze/thaw \s-1API\s0 for internal serialization..IP "DumpFile(filepath, list)" 4.IX Item "DumpFile(filepath, list)"Writes the \s-1YAML\s0 stream to a file instead of just returning a string..IP "LoadFile(filepath)" 4.IX Item "LoadFile(filepath)"Reads the \s-1YAML\s0 stream from a file instead of a string..IP "Bless(perl\-node, [yaml\-node | class\-name])" 4.IX Item "Bless(perl-node, [yaml-node | class-name])"Associate a normal Perl node, with a yaml node. A yaml node is an objecttied to the YAML::Node class. The second argument is either a yaml nodethat you've already created or a class (package) name that supports a\&\fIyaml_dump()\fR function. A \fIyaml_dump()\fR function should take a perl node andreturn a yaml node. If no second argument is provided, Bless will createa yaml node. This node is not returned, but can be retrieved with the\&\fIBlessed()\fR function..SpHere's an example of how to use Bless. Say you have a hash containingthree keys, but you only want to dump two of them. Furthermore the keysmust be dumped in a certain order. Here's how you do that:.Sp.Vb 5\& use YAML qw(Dump Bless);\& $hash = {apple => \*(Aqgood\*(Aq, banana => \*(Aqbad\*(Aq, cauliflower => \*(Aqugly\*(Aq};\& print Dump $hash;\& Bless($hash)\->keys([\*(Aqbanana\*(Aq, \*(Aqapple\*(Aq]);\& print Dump $hash;.Ve.Spproduces:.Sp.Vb 7\& \-\-\-\& apple: good\& banana: bad\& cauliflower: ugly\& \-\-\-\& banana: bad\& apple: good.Ve.SpBless returns the tied part of a yaml-node, so that you can call theYAML::Node methods. This is the same thing that \fIYAML::Node::ynode()\fRreturns. So another way to do the above example is:.Sp.Vb 8\& use YAML qw(Dump Bless);\& use YAML::Node;\& $hash = {apple => \*(Aqgood\*(Aq, banana => \*(Aqbad\*(Aq, cauliflower => \*(Aqugly\*(Aq};\& print Dump $hash;\& Bless($hash);\& $ynode = ynode(Blessed($hash));\& $ynode\->keys([\*(Aqbanana\*(Aq, \*(Aqapple\*(Aq]);\& print Dump $hash;.Ve.SpNote that Blessing a Perl data structure does not change it anyway. Theextra information is stored separately and looked up by the Blessednode's memory address..IP "Blessed(perl\-node)" 4.IX Item "Blessed(perl-node)"Returns the yaml node that a particular perl node is associated with(see above). Returns undef if the node is not (\s-1YAML\s0) Blessed..SH "GLOBAL OPTIONS".IX Header "GLOBAL OPTIONS"\&\s-1YAML\s0 options are set using a group of global variables in the \s-1YAML\s0namespace. This is similar to how Data::Dumper works..PPFor example, to change the indentation width, do something like:.PP.Vb 1\& local $YAML::Indent = 3;.Ve
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -