{
    "content": [
        {
            "type": "text",
            "text": "# Algorithm::C3 (perldoc)\n\n## NAME\n\nAlgorithm::C3 - A module for merging hierarchies using the C3 algorithm\n\n## SYNOPSIS\n\nuse Algorithm::C3;\n# merging a classic diamond\n# inheritance graph like this:\n#\n#    <A>\n#   /   \\\n# <B>   <C>\n#   \\   /\n#    <D>\nmy @merged = Algorithm::C3::merge(\n'D',\nsub {\n# extract the ISA array\n# from the package\nno strict 'refs';\n@{$[0] . '::ISA'};\n}\n);\nprint join \", \" => @merged; # prints D, B, C, A\n\n## DESCRIPTION\n\nThis module implements the C3 algorithm. I have broken this out into it's own module because I\nfound myself copying and pasting it way too often for various needs. Most of the uses I have for\nC3 revolve around class building and metamodels, but it could also be used for things like\ndependency resolution as well since it tends to do such a nice job of preserving local\nprecedence orderings.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (1 subsections)\n- **FUNCTION**\n- **CODE COVERAGE**\n- **SEE ALSO** (4 subsections)\n- **AUTHORS**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Algorithm::C3",
        "section": "",
        "mode": "perldoc",
        "summary": "Algorithm::C3 - A module for merging hierarchies using the C3 algorithm",
        "synopsis": "use Algorithm::C3;\n# merging a classic diamond\n# inheritance graph like this:\n#\n#    <A>\n#   /   \\\n# <B>   <C>\n#   \\   /\n#    <D>\nmy @merged = Algorithm::C3::merge(\n'D',\nsub {\n# extract the ISA array\n# from the package\nno strict 'refs';\n@{$[0] . '::ISA'};\n}\n);\nprint join \", \" => @merged; # prints D, B, C, A",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 23,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 16,
                "subsections": [
                    {
                        "name": "How does C3 work.",
                        "lines": 17
                    }
                ]
            },
            {
                "name": "FUNCTION",
                "lines": 45,
                "subsections": []
            },
            {
                "name": "CODE COVERAGE",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 1,
                "subsections": [
                    {
                        "name": "The original Dylan paper",
                        "lines": 2
                    },
                    {
                        "name": "The prototype Perl 6 Object Model uses C3",
                        "lines": 2
                    },
                    {
                        "name": "Parrot now uses C3",
                        "lines": 3
                    },
                    {
                        "name": "Python 2.3 MRO related links",
                        "lines": 6
                    }
                ]
            },
            {
                "name": "AUTHORS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 7,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Algorithm::C3 - A module for merging hierarchies using the C3 algorithm\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Algorithm::C3;\n\n# merging a classic diamond\n# inheritance graph like this:\n#\n#    <A>\n#   /   \\\n# <B>   <C>\n#   \\   /\n#    <D>\n\nmy @merged = Algorithm::C3::merge(\n'D',\nsub {\n# extract the ISA array\n# from the package\nno strict 'refs';\n@{$[0] . '::ISA'};\n}\n);\n\nprint join \", \" => @merged; # prints D, B, C, A\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module implements the C3 algorithm. I have broken this out into it's own module because I\nfound myself copying and pasting it way too often for various needs. Most of the uses I have for\nC3 revolve around class building and metamodels, but it could also be used for things like\ndependency resolution as well since it tends to do such a nice job of preserving local\nprecedence orderings.\n\nBelow is a brief explanation of C3 taken from the Class::C3 module. For more detailed\ninformation, see the \"SEE ALSO\" section and the links there.\n\nWhat is C3?\nC3 is the name of an algorithm which aims to provide a sane method resolution order under\nmultiple inheritance. It was first introduced in the language Dylan (see links in the \"SEE ALSO\"\nsection), and then later adopted as the preferred MRO (Method Resolution Order) for the\nnew-style classes in Python 2.3. Most recently it has been adopted as the 'canonical' MRO for\nPerl 6 classes, and the default MRO for Parrot objects as well.\n",
                "subsections": [
                    {
                        "name": "How does C3 work.",
                        "content": "C3 works by always preserving local precedence ordering. This essentially means that no class\nwill appear before any of it's subclasses. Take the classic diamond inheritance pattern for\ninstance:\n\n<A>\n/   \\\n<B>   <C>\n\\   /\n<D>\n\nThe standard Perl 5 MRO would be (D, B, A, C). The result being that A appears before C, even\nthough C is the subclass of A. The C3 MRO algorithm however, produces the following MRO (D, B,\nC, A), which does not have this same issue.\n\nThis example is fairly trivial, for more complex examples and a deeper explanation, see the\nlinks in the \"SEE ALSO\" section.\n"
                    }
                ]
            },
            "FUNCTION": {
                "content": "merge ($root, $functofetchparent, $cache)\nThis takes a $root node, which can be anything really it is up to you. Then it takes a\n$functofetchparent which can be either a CODE reference (see SYNOPSIS above for an\nexample), or a string containing a method name to be called on all the items being\nlinearized. An example of how this might look is below:\n\n{\npackage A;\n\nsub supers {\nno strict 'refs';\n@{$[0] . '::ISA'};\n}\n\npackage C;\nour @ISA = ('A');\npackage B;\nour @ISA = ('A');\npackage D;\nour @ISA = ('B', 'C');\n}\n\nprint join \", \" => Algorithm::C3::merge('D', 'supers');\n\nThe purpose of $functofetchparent is to provide a way for \"merge\" to extract the parents\nof $root. This is needed for C3 to be able to do it's work.\n\nThe $cache parameter is an entirely optional performance measure, and should not change\nbehavior.\n\nIf supplied, it should be a hashref that merge can use as a private cache between runs to\nspeed things up. Generally speaking, if you will be calling merge many times on related\nthings, and the parent fetching function will return constant results given the same\narguments during all of these calls, you can and should reuse the same shared cache hash for\nall of the calls. Example:\n\nsub dosomemerging {\nmy %mergecache;\nmy @foomro = Algorithm::C3::Merge('Foo', \\&getsupers, \\%mergecache);\nmy @barmro = Algorithm::C3::Merge('Bar', \\&getsupers, \\%mergecache);\nmy @bazmro = Algorithm::C3::Merge('Baz', \\&getsupers, \\%mergecache);\nmy @quuxmro = Algorithm::C3::Merge('Quux', \\&getsupers, \\%mergecache);\n# ...\n}\n",
                "subsections": []
            },
            "CODE COVERAGE": {
                "content": "I use Devel::Cover to test the code coverage of my tests, below is the Devel::Cover report on\nthis module's test suite.\n\n------------------------ ------ ------ ------ ------ ------ ------ ------\nFile                       stmt   bran   cond    sub    pod   time  total\n------------------------ ------ ------ ------ ------ ------ ------ ------\nAlgorithm/C3.pm           100.0  100.0  100.0  100.0  100.0  100.0  100.0\n------------------------ ------ ------ ------ ------ ------ ------ ------\nTotal                     100.0  100.0  100.0  100.0  100.0  100.0  100.0\n------------------------ ------ ------ ------ ------ ------ ------ ------\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "",
                "subsections": [
                    {
                        "name": "The original Dylan paper",
                        "content": "<http://www.webcom.com/haahr/dylan/linearization-oopsla96.html>\n"
                    },
                    {
                        "name": "The prototype Perl 6 Object Model uses C3",
                        "content": "<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel/>\n"
                    },
                    {
                        "name": "Parrot now uses C3",
                        "content": "<http://aspn.activestate.com/ASPN/Mail/Message/perl6-internals/2746631>\n<http://use.perl.org/~autrijus/journal/25768>\n"
                    },
                    {
                        "name": "Python 2.3 MRO related links",
                        "content": "<http://www.python.org/2.3/mro.html>\n<http://www.python.org/2.2.2/descrintro.html#mro>\n\nC3 for TinyCLOS\n<http://www.call-with-current-continuation.org/eggs/c3.html>\n"
                    }
                ]
            },
            "AUTHORS": {
                "content": "Stevan Little, <stevan@iinteractive.com>\n\nBrandon L. Black, <blblack@gmail.com>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "Copyright 2006 by Infinity Interactive, Inc.\n\n<http://www.iinteractive.com>\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            }
        }
    }
}