{
    "content": [
        {
            "type": "text",
            "text": "# Data::Serializer::Cookbook (perldoc)\n\n## NAME\n\nCookbook - Examples of how to use Data::Serializer\n\n## DESCRIPTION\n\nData::Serializer::Cookbook is a collection of solutions for using Data::Serializer.\n\n## Sections\n\n- **NAME**\n- **DESCRIPTION**\n- **CONVENTIONS**\n- **Encrypting your data** (1 subsections)\n- **Compressing your data** (1 subsections)\n- **You want to read in data serialized outside of Data::Serializer** (1 subsections)\n- **You want to write serialized data in a form understood outside of Data::Serializer** (1 subsections)\n- **You want to convert data between two different serializers native formats** (2 subsections)\n- **AUTHOR**\n- **COPYRIGHT**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Data::Serializer::Cookbook",
        "section": "",
        "mode": "perldoc",
        "summary": "Cookbook - Examples of how to use Data::Serializer",
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "Serializer",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/Serializer/3/json"
            },
            {
                "name": "Raw",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/Raw/3/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "CONVENTIONS",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "Encrypting your data",
                "lines": 3,
                "subsections": [
                    {
                        "name": "Solution",
                        "lines": 12
                    }
                ]
            },
            {
                "name": "Compressing your data",
                "lines": 2,
                "subsections": [
                    {
                        "name": "Solution",
                        "lines": 12
                    }
                ]
            },
            {
                "name": "You want to read in data serialized outside of Data::Serializer",
                "lines": 4,
                "subsections": [
                    {
                        "name": "Solution",
                        "lines": 6
                    }
                ]
            },
            {
                "name": "You want to write serialized data in a form understood outside of Data::Serializer",
                "lines": 4,
                "subsections": [
                    {
                        "name": "Solution",
                        "lines": 6
                    }
                ]
            },
            {
                "name": "You want to convert data between two different serializers native formats",
                "lines": 2,
                "subsections": [
                    {
                        "name": "Solution",
                        "lines": 15
                    },
                    {
                        "name": "Solution",
                        "lines": 15
                    }
                ]
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 3,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Cookbook - Examples of how to use Data::Serializer\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Data::Serializer::Cookbook is a collection of solutions for using Data::Serializer.\n",
                "subsections": []
            },
            "CONVENTIONS": {
                "content": "Unless otherwise specified, all examples can be assumed to begin with:\n\nuse Data::Serializer;\n\nmy $serializer = Data::Serializer->new();\n\nSome examples will show different arguments to the new method, where specified simply use that\nline instead of the simple form above.\n\nCONVENTIONS for Raw Access\nFort hose who want a straight pass through to the underlying serializer, where nothing else is\ndone (no encoding, encryption, compression, etc) there is Data::Serializer::Raw(3).\n\nThese begin like this:\n\nuse Data::Serializer::Raw;\n\nmy $rawserializer = Data::Serializer::Raw->new();\n",
                "subsections": []
            },
            "Encrypting your data": {
                "content": "You wish to encrypt your data structure, so that it can only be decoded by someone who shares\nthe same key.\n",
                "subsections": [
                    {
                        "name": "Solution",
                        "content": "$serializer->secret('mysecret');\n\nmy $encryptedhashref = $serializer->serializer($hash);\n\n... (in other program) ...\n\n$serializer->secret('mysecret');\n\nmy $clearhash = $serializer->deserializer($encryptedhash);\n\nNote: You will have to have the Crypt::CBC module installed for this to work.\n"
                    }
                ]
            },
            "Compressing your data": {
                "content": "You wish to compress your data structure to cut down on how much disk space it will take up.\n",
                "subsections": [
                    {
                        "name": "Solution",
                        "content": "$serializer->compress(1);\n\nmy $compressedhashref = $serializer->serializer($hash);\n\n... (in other program) ...\n\nmy $clearhash = $serializer->deserializer($compressedhash);\n\nNote: You will have to have the Compress::Zlib module installed for this to work. Your mileage\nwill vary dramatically depending on what serializer you use. Some serializers are already fairly\ncompact.\n"
                    }
                ]
            },
            "You want to read in data serialized outside of Data::Serializer": {
                "content": "You need to write a program that can read in data serialized in a format other than\nData::Serializer. For example you need to be able to be able to process data serialized by\nXML::Dumper.\n",
                "subsections": [
                    {
                        "name": "Solution",
                        "content": "use Data::Serializer::Raw;\n\nmy $xmlrawserializer = Data::Serializer::Raw->(serializer => 'XML::Dumper');\n\nmy $hashref = $xmlrawserializer->deserialize($xmldata);\n"
                    }
                ]
            },
            "You want to write serialized data in a form understood outside of Data::Serializer": {
                "content": "You need to write a program that can write out data in a format other than Data::Serializer. Or\nsaid more generically you need to write out data in the format native to the underlying\nserializer. For our example we will be exporting data using XML::Dumper format.\n",
                "subsections": [
                    {
                        "name": "Solution",
                        "content": "ues Data::Serializer::Raw;\n\nmy $xmlrawserializer = Data::Serializer::Raw->(serializer => 'XML::Dumper');\n\nmy $xmldata = $xmlrawserializer->serialize($hashref);\n"
                    }
                ]
            },
            "You want to convert data between two different serializers native formats": {
                "content": "You have data serialized by php that you want to convert to xml for use by other programs.\n",
                "subsections": [
                    {
                        "name": "Solution",
                        "content": "use Data::Serializer::Raw;\n\nmy $xmlrawserializer = Data::Serializer::Raw->(serializer => 'XML::Dumper');\n\nmy $phprawserializer = Data::Serializer::Raw->(serializer => 'PHP::Serialization');\n\nmy $hashref = $phprawserializer->deserialize($phpdata);\n\nmy $xmldata = $xmlrawserializer->serialize($hashref);\n\nKeeping data persistent between executions of a program.\nYou have a program that you run every 10 minutes, it uses SNMP to pull some counters from one of\nyour routers. You want your program to keep the counters from the last run so that it can see\nhow much traffic has passed over a link since it last ran.\n"
                    },
                    {
                        "name": "Solution",
                        "content": "# path to store our serialized data\n# be paranoid, use full paths\nmy $lastrundatafile = '/full/path/to/file/lastrun.data';\n\n#We keep our data as a hash reference\nmy $lastdata = $serializer->retrieve($lastrundatafile);\n\n#Pull in our new data through 'pulldata()';\nmy $newdata = queryrouter($router);\n\n#run comparison code\nruncomparison($lastdata,$newdata);\n\n$serializer->store($newdata);\n"
                    }
                ]
            },
            "AUTHOR": {
                "content": "Neil Neely <neil@neely.cx>.\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (c) 2001-2011 Neil Neely. All rights reserved.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Data::Serializer(3)\nData::Serializer::Raw(3)\n",
                "subsections": []
            }
        }
    }
}