{
    "content": [
        {
            "type": "text",
            "text": "# IO::Wrap (perldoc)\n\n## NAME\n\nIO::Wrap - wrap raw filehandles in IO::Handle interface\n\n## SYNOPSIS\n\nuse IO::Wrap;\n### Do stuff with any kind of filehandle (including a bare globref), or\n### any kind of blessed object that responds to a print() message.\n###\nsub dostuff {\nmy $fh = shift;\n### At this point, we have no idea what the user gave us...\n### a globref? a FileHandle? a scalar filehandle name?\n$fh = wraphandle($fh);\n### At this point, we know we have an IO::Handle-like object!\n$fh->print(\"Hey there!\");\n...\n}\n\n## DESCRIPTION\n\nLet's say you want to write some code which does I/O, but you don't want to force the caller to\nprovide you with a FileHandle or IO::Handle object. You want them to be able to say:\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **NOTES**\n- **WARNINGS**\n- **VERSION**\n- **AUTHOR**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "IO::Wrap",
        "section": "",
        "mode": "perldoc",
        "summary": "IO::Wrap - wrap raw filehandles in IO::Handle interface",
        "synopsis": "use IO::Wrap;\n### Do stuff with any kind of filehandle (including a bare globref), or\n### any kind of blessed object that responds to a print() message.\n###\nsub dostuff {\nmy $fh = shift;\n### At this point, we have no idea what the user gave us...\n### a globref? a FileHandle? a scalar filehandle name?\n$fh = wraphandle($fh);\n### At this point, we know we have an IO::Handle-like object!\n$fh->print(\"Hey there!\");\n...\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 42,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "WARNINGS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "IO::Wrap - wrap raw filehandles in IO::Handle interface\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use IO::Wrap;\n\n### Do stuff with any kind of filehandle (including a bare globref), or\n### any kind of blessed object that responds to a print() message.\n###\nsub dostuff {\nmy $fh = shift;\n\n### At this point, we have no idea what the user gave us...\n### a globref? a FileHandle? a scalar filehandle name?\n\n$fh = wraphandle($fh);\n\n### At this point, we know we have an IO::Handle-like object!\n\n$fh->print(\"Hey there!\");\n...\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Let's say you want to write some code which does I/O, but you don't want to force the caller to\nprovide you with a FileHandle or IO::Handle object. You want them to be able to say:\n\ndostuff(\\*STDOUT);\ndostuff('STDERR');\ndostuff($someFileHandleobject);\ndostuff($someIOHandleobject);\n\nAnd even:\n\ndostuff($anyobjectwithaprintmethod);\n\nSure, one way to do it is to force the caller to use tiehandle(). But that puts the burden on\nthem. Another way to do it is to use IO::Wrap, which provides you with the following functions:\n\nwraphandle SCALAR\nThis function will take a single argument, and \"wrap\" it based on what it seems to be...\n\n*   A raw scalar filehandle name, like \"STDOUT\" or \"Class::HANDLE\". In this case, the\nfilehandle name is wrapped in an IO::Wrap object, which is returned.\n\n*   A raw filehandle glob, like \"\\*STDOUT\". In this case, the filehandle glob is wrapped in\nan IO::Wrap object, which is returned.\n\n*   A blessed FileHandle object. In this case, the FileHandle is wrapped in an IO::Wrap\nobject if and only if your FileHandle class does not support the \"read()\" method.\n\n*   Any other kind of blessed object, which is assumed to be already conformant to the\nIO::Handle interface. In this case, you just get back that object.\n\nIf you get back an IO::Wrap object, it will obey a basic subset of the IO:: interface. That is,\nthe following methods (note: I said *methods*, not named operators) should work on the thing you\nget back:\n\nclose\ngetline\ngetlines\nprint ARGS...\nread BUFFER,NBYTES\nseek POS,WHENCE\ntell\n",
                "subsections": []
            },
            "NOTES": {
                "content": "Clearly, when wrapping a raw external filehandle (like \\*STDOUT), I didn't want to close the\nfile descriptor when the \"wrapper\" object is destroyed... since the user might not appreciate\nthat! Hence, there's no DESTROY method in this class.\n\nWhen wrapping a FileHandle object, however, I believe that Perl will invoke the\nFileHandle::DESTROY when the last reference goes away, so in that case, the filehandle is closed\nif the wrapped FileHandle really was the last reference to it.\n",
                "subsections": []
            },
            "WARNINGS": {
                "content": "This module does not allow you to wrap filehandle names which are given as strings that lack the\npackage they were opened in. That is, if a user opens FOO in package Foo, they must pass it to\nyou either as \"\\*FOO\" or as \"Foo::FOO\". However, \"STDIN\" and friends will work just fine.\n",
                "subsections": []
            },
            "VERSION": {
                "content": "$Id: Wrap.pm,v 1.2 2005/02/10 21:21:53 dfs Exp $\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Primary Maintainer\nDianne Skoll (dfs@roaringpenguin.com).\n\nOriginal Author\nEryq (eryq@zeegee.com). President, ZeeGee Software Inc (http://www.zeegee.com).\n",
                "subsections": []
            }
        }
    }
}