.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .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" '' . ds C` . ds C' '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 (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" 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 "Data::Serializer::Cookbook 3pm" .TH Data::Serializer::Cookbook 3pm "2015-06-01" "perl v5.20.2" "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" Cookbook \- Examples of how to use Data::Serializer .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBData::Serializer::Cookbook\fR is a collection of solutions for using \fBData::Serializer\fR. .SH "CONVENTIONS" .IX Header "CONVENTIONS" Unless otherwise specified, all examples can be assumed to begin with: .PP .Vb 1 \& use Data::Serializer; \& \& my $serializer = Data::Serializer\->new(); .Ve .PP Some examples will show different arguments to the \fBnew\fR method, where specified simply use that line instead of the simple form above. .SH "CONVENTIONS for Raw Access" .IX Header "CONVENTIONS for Raw Access" Fort hose who want a straight pass through to the underlying serializer, where nothing else is done (no encoding, encryption, compression, etc) there is \fIData::Serializer::Raw\fR\|(3). .PP These begin like this: .PP .Vb 1 \& use Data::Serializer::Raw; \& \& my $raw_serializer = Data::Serializer::Raw\->new(); .Ve .SH "Encrypting your data" .IX Header "Encrypting your data" You wish to encrypt your data structure, so that it can only be decoded by someone who shares the same key. .SS "Solution" .IX Subsection "Solution" .Vb 1 \& $serializer\->secret(\*(Aqmysecret\*(Aq); \& \& my $encrypted_hashref = $serializer\->serializer($hash); \& \& ... (in other program) ... \& \& $serializer\->secret(\*(Aqmysecret\*(Aq); \& \& my $clear_hash = $serializer\->deserializer($encrypted_hash); .Ve .PP Note: You will have to have the Crypt::CBC module installed for this to work. .SH "Compressing your data" .IX Header "Compressing your data" You wish to compress your data structure to cut down on how much disk space it will take up. .SS "Solution" .IX Subsection "Solution" .Vb 1 \& $serializer\->compress(1); \& \& my $compressed_hashref = $serializer\->serializer($hash); \& \& ... (in other program) ... \& \& my $clear_hash = $serializer\->deserializer($compressed_hash); .Ve .PP Note: You will have to have the Compress::Zlib module installed for this to work. Your mileage will vary dramatically depending on what serializer you use. Some serializers are already fairly compact. .SH "You want to read in data serialized outside of Data::Serializer" .IX Header "You want to read in data serialized outside of Data::Serializer" You need to write a program that can read in data serialized in a format other than Data::Serializer. For example you need to be able to be able to process data serialized by XML::Dumper. .SS "Solution" .IX Subsection "Solution" .Vb 1 \& use Data::Serializer::Raw; \& \& my $xml_raw_serializer = Data::Serializer::Raw\->(serializer => \*(AqXML::Dumper\*(Aq); \& \& my $hash_ref = $xml_raw_serializer\->deserialize($xml_data); .Ve .SH "You want to write serialized data in a form understood outside of Data::Serializer" .IX Header "You want to write serialized data in a form understood outside of Data::Serializer" You need to write a program that can write out data in a format other than Data::Serializer. Or said more generically you need to write out data in the format native to the underlying serializer. For our example we will be exporting data using XML::Dumper format. .SS "Solution" .IX Subsection "Solution" .Vb 1 \& ues Data::Serializer::Raw; \& \& my $xml_raw_serializer = Data::Serializer::Raw\->(serializer => \*(AqXML::Dumper\*(Aq); \& \& my $xml_data = $xml_raw_serializer\->serialize($hash_ref); .Ve .SH "You want to convert data between two different serializers native formats" .IX Header "You want to convert data between two different serializers native formats" You have data serialized by php that you want to convert to xml for use by other programs. .SS "Solution" .IX Subsection "Solution" .Vb 1 \& use Data::Serializer::Raw; \& \& my $xml_raw_serializer = Data::Serializer::Raw\->(serializer => \*(AqXML::Dumper\*(Aq); \& \& my $php_raw_serializer = Data::Serializer::Raw\->(serializer => \*(AqPHP::Serialization\*(Aq); \& \& my $hash_ref = $php_raw_serializer\->deserialize($php_data); \& \& my $xml_data = $xml_raw_serializer\->serialize($hash_ref); .Ve .SH "Keeping data persistent between executions of a program." .IX Header "Keeping data persistent between executions of a program." You have a program that you run every 10 minutes, it uses \s-1SNMP\s0 to pull some counters from one of your routers. You want your program to keep the counters from the last run so that it can see how much traffic has passed over a link since it last ran. .SS "Solution" .IX Subsection "Solution" .Vb 3 \& # path to store our serialized data \& # be paranoid, use full paths \& my $last_run_datafile = \*(Aq/full/path/to/file/lastrun.data\*(Aq; \& \& #We keep our data as a hash reference \& my $last_data = $serializer\->retrieve($last_run_datafile); \& \& #Pull in our new data through \*(Aqpull_data()\*(Aq; \& my $new_data = query_router($router); \& \& #run comparison code \& run_comparison($last_data,$new_data); \& \& $serializer\->store($new_data); .Ve .SH "AUTHOR" .IX Header "AUTHOR" Neil Neely <\fIneil@neely.cx\fR>. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2001\-2011 Neil Neely. All rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\fIData::Serializer\fR\|(3)" 4 .IX Item "Data::Serializer" .PD 0 .IP "\fIData::Serializer::Raw\fR\|(3)" 4 .IX Item "Data::Serializer::Raw"