{
    "content": [
        {
            "type": "text",
            "text": "# Test2::Event (perldoc)\n\n## NAME\n\nTest2::Event - Base class for events\n\n## SYNOPSIS\n\npackage Test2::Event::MyEvent;\nuse strict;\nuse warnings;\n# This will make our class an event subclass (required)\nuse base 'Test2::Event';\n# Add some accessors (optional)\n# You are not obligated to use HashBase, you can use any object tool you\n# want, or roll your own accessors.\nuse Test2::Util::HashBase qw/foo bar baz/;\n# Use this if you want the legacy API to be written for you, for this to\n# work you will need to implement a facetdata() method.\nuse Test2::Util::Facets2Legacy;\n# Chance to initialize some defaults\nsub init {\nmy $self = shift;\n# no other args in @\n$self->setfoo('xxx') unless defined $self->foo;\n...\n}\n# This is the new way for events to convey data to the Test2 system\nsub facetdata {\nmy $self = shift;\n# Get common facets such as 'about', 'trace' 'amnesty', and 'meta'\nmy $facetdata = $self->commonfacetdata();\n# Are you making an assertion?\n$facetdata->{assert} = {pass => 1, details => 'my assertion'};\n...\nreturn $facetdata;\n}\n1;\n\n## DESCRIPTION\n\nBase class for all event objects that get passed through Test2.\n\n## Sections\n\n- **NAME**\n- **DESCRIPTION**\n- **SYNOPSIS**\n- **METHODS**\n- **THIRD PARTY META-DATA**\n- **SOURCE**\n- **MAINTAINERS**\n- **AUTHORS**\n- **COPYRIGHT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Test2::Event",
        "section": "",
        "mode": "perldoc",
        "summary": "Test2::Event - Base class for events",
        "synopsis": "package Test2::Event::MyEvent;\nuse strict;\nuse warnings;\n# This will make our class an event subclass (required)\nuse base 'Test2::Event';\n# Add some accessors (optional)\n# You are not obligated to use HashBase, you can use any object tool you\n# want, or roll your own accessors.\nuse Test2::Util::HashBase qw/foo bar baz/;\n# Use this if you want the legacy API to be written for you, for this to\n# work you will need to implement a facetdata() method.\nuse Test2::Util::Facets2Legacy;\n# Chance to initialize some defaults\nsub init {\nmy $self = shift;\n# no other args in @\n$self->setfoo('xxx') unless defined $self->foo;\n...\n}\n# This is the new way for events to convey data to the Test2 system\nsub facetdata {\nmy $self = shift;\n# Get common facets such as 'about', 'trace' 'amnesty', and 'meta'\nmy $facetdata = $self->commonfacetdata();\n# Are you making an assertion?\n$facetdata->{assert} = {pass => 1, details => 'my assertion'};\n...\nreturn $facetdata;\n}\n1;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 42,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 270,
                "subsections": []
            },
            {
                "name": "THIRD PARTY META-DATA",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SOURCE",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "MAINTAINERS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 7,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Test2::Event - Base class for events\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Base class for all event objects that get passed through Test2.\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "package Test2::Event::MyEvent;\nuse strict;\nuse warnings;\n\n# This will make our class an event subclass (required)\nuse base 'Test2::Event';\n\n# Add some accessors (optional)\n# You are not obligated to use HashBase, you can use any object tool you\n# want, or roll your own accessors.\nuse Test2::Util::HashBase qw/foo bar baz/;\n\n# Use this if you want the legacy API to be written for you, for this to\n# work you will need to implement a facetdata() method.\nuse Test2::Util::Facets2Legacy;\n\n# Chance to initialize some defaults\nsub init {\nmy $self = shift;\n# no other args in @\n\n$self->setfoo('xxx') unless defined $self->foo;\n\n...\n}\n\n# This is the new way for events to convey data to the Test2 system\nsub facetdata {\nmy $self = shift;\n\n# Get common facets such as 'about', 'trace' 'amnesty', and 'meta'\nmy $facetdata = $self->commonfacetdata();\n\n# Are you making an assertion?\n$facetdata->{assert} = {pass => 1, details => 'my assertion'};\n...\n\nreturn $facetdata;\n}\n\n1;\n",
                "subsections": []
            },
            "METHODS": {
                "content": "GENERAL\n$trace = $e->trace\nGet a snapshot of the Test2::EventFacet::Trace as it was when this event was generated\n\n$boolorundef = $e->related($e2)\nCheck if 2 events are related. In this case related means their traces share a signature\nmeaning they were created with the same context (or at the very least by contexts which\nshare an id, which is the same thing unless someone is doing something very bad).\n\nThis can be used to reliably link multiple events created by the same tool. For instance a\nfailing test like \"ok(0, \"fail\"\" will generate 2 events, one being a Test2::Event::Ok, the\nother being a Test2::Event::Diag, both of these events are related having been created under\nthe same context and by the same initial tool (though multiple tools may have been nested\nunder the initial one).\n\nThis will return \"undef\" if the relationship cannot be checked, which happens if either\nevent has an incomplete or missing trace. This will return 0 if the traces are complete, but\ndo not match. 1 will be returned if there is a match.\n\n$e->addamnesty({tag => $TAG, details => $DETAILS});\nThis can be used to add amnesty to this event. Amnesty only effects failing assertions in\nmost cases, but some formatters may display them for passing assertions, or even\nnon-assertions as well.\n\nAmnesty will prevent a failed assertion from causing the overall test to fail. In other\nwords it marks a failure as expected and allowed.\n\nNote: This is how 'TODO' is implemented under the hood. TODO is essentially amnesty with the\n'TODO' tag. The details are the reason for the TODO.\n\n$uuid = $e->uuid\nIf UUID tagging is enabled (See Test::API) then any event that has made its way through a\nhub will be tagged with a UUID. A newly created event will not yet be tagged in most cases.\n\n$class = $e->loadfacet($name)\nThis method is used to load a facet by name (or key). It will attempt to load the facet\nclass, if it succeeds it will return the class it loaded. If it fails it will return\n\"undef\". This caches the result at the class level so that future calls will be faster.\n\nThe $name variable should be the key used to access the facet in a facets hashref. For\ninstance the assertion facet has the key 'assert', the information facet has the 'info' key,\nand the error facet has the key 'errors'. You may include or omit the 's' at the end of the\nname, the method is smart enough to try both the 's' and no-'s' forms, it will check what\nyou provided first, and if that is not found it will add or strip the 's and try again.\n\n@classes = $e->FACETTYPES()\n@classes = Test2::Event->FACETTYPES()\nThis returns a list of all facets that have been loaded using the \"loadfacet()\" method.\nThis will not return any classes that have not been loaded, or have been loaded directly\nwithout a call to \"loadfacet()\".\n\nNote: The core facet types are automatically loaded and populated in this list.\n\nNEW API\n$hashref = $e->commonfacetdata();\nThis can be used by subclasses to generate a starting facet data hashref. This will populate\nthe hashref with the trace, meta, amnesty, and about facets. These facets are nearly always\nproduced the same way for all events.\n\n$hashref = $e->facetdata()\nIf you do not override this then the default implementation will attempt to generate facets\nfrom the legacy API. This generation is limited only to what the legacy API can provide. It\nis recommended that you override this method and write out explicit facet data.\n\n$hashref = $e->facets()\nThis takes the hashref from \"facetdata()\" and blesses each facet into the proper\n\"Test2::EventFacet::*\" subclass. If no class can be found for any given facet it will be\npassed along unchanged.\n\n@errors = $e->validatefacetdata();\n@errors = $e->validatefacetdata(%params);\n@errors = $e->validatefacetdata(\\%facets, %params);\n@errors = Test2::Event->validatefacetdata(%params);\n@errors = Test2::Event->validatefacetdata(\\%facets, %params);\nThis method will validate facet data and return a list of errors. If no errors are found\nthis will return an empty list.\n\nThis can be called as an object method with no arguments, in which case the \"facetdata()\"\nmethod will be called to get the facet data to be validated.\n\nWhen used as an object method the \"\\%facetdata\" argument may be omitted.\n\nWhen used as a class method the \"\\%facetdata\" argument is required.\n\nRemaining arguments will be slurped into a %params hash.\n\nCurrently only 1 parameter is defined:\n\nrequirefacetclass => $BOOL\nWhen set to true (default is false) this will reject any facets where a facet class\ncannot be found. Normally facets without classes are assumed to be custom and are\nignored.\n\nWHAT ARE FACETS?\nFacets are how events convey their purpose to the Test2 internals and formatters. An event\nwithout facets will have no intentional effect on the overall test state, and will not be\ndisplayed at all by most formatters, except perhaps to say that an event of an unknown type was\nseen.\n\nFacets are produced by the \"facetdata()\" subroutine, which you should nearly-always override.\n\"facetdata()\" is expected to return a hashref where each key is the facet type, and the value\nis either a hashref with the data for that facet, or an array of hashrefs. Some facets must be\ndefined as single hashrefs, some must be defined as an array of hashrefs, No facets allow both.\n\n\"facetdata()\" MUST NOT bless the data it returns, the main hashref, and nested facet hashrefs\nMUST be bare, though items contained within each facet may be blessed. The data returned by this\nmethod should also be copies of the internal data in order to prevent accidental state\nmodification.\n\n\"facets()\" takes the data from \"facetdata()\" and blesses it into the \"Test2::EventFacet::*\"\npackages. This is rarely used however, the EventFacet packages are primarily for convenience and\ndocumentation. The EventFacet classes are not used at all internally, instead the raw data is\nused.\n\nHere is a list of facet types by package. The packages are not used internally, but are where\nthe documentation for each type is kept.\n\nNote: Every single facet type has the 'details' field. This field is always intended for human\nconsumption, and when provided, should explain the 'why' for the facet. All other fields are\nfacet specific.\n\nabout => {...}\nTest2::EventFacet::About\n\nThis contains information about the event itself such as the event package name. The\n\"details\" field for this facet is an overall summary of the event.\n\nassert => {...}\nTest2::EventFacet::Assert\n\nThis facet is used if an assertion was made. The \"details\" field of this facet is the\ndescription of the assertion.\n\ncontrol => {...}\nTest2::EventFacet::Control\n\nThis facet is used to tell the Test2::Event::Hub about special actions the event causes.\nThings like halting all testing, terminating the current test, etc. In this facet the\n\"details\" field explains why any special action was taken.\n\nNote: This is how bail-out is implemented.\n\nmeta => {...}\nTest2::EventFacet::Meta\n\nThe meta facet contains all the meta-data attached to the event. In this case the \"details\"\nfield has no special meaning, but may be present if something sets the 'details' meta-key on\nthe event.\n\nparent => {...}\nTest2::EventFacet::Parent\n\nThis facet contains nested events and similar details for subtests. In this facet the\n\"details\" field will typically be the name of the subtest.\n\nplan => {...}\nTest2::EventFacet::Plan\n\nThis facet tells the system that a plan has been set. The \"details\" field of this is usually\nleft empty, but when present explains why the plan is what it is, this is most useful if the\nplan is to skip-all.\n\ntrace => {...}\nTest2::EventFacet::Trace\n\nThis facet contains information related to when and where the event was generated. This is\nhow the test file and line number of a failure is known. This facet can also help you to\ntell if tests are related.\n\nIn this facet the \"details\" field overrides the \"failed at testfile.t line 42.\" message\nprovided on assertion failure.\n\namnesty => [{...}, ...]\nTest2::EventFacet::Amnesty\n\nThe amnesty facet is a list instead of a single item, this is important as amnesty can come\nfrom multiple places at once.\n\nFor each instance of amnesty the \"details\" field explains why amnesty was granted.\n\nNote: Outside of formatters amnesty only acts to forgive a failing assertion.\n\nerrors => [{...}, ...]\nTest2::EventFacet::Error\n\nThe errors facet is a list instead of a single item, any number of errors can be listed. In\nthis facet \"details\" describes the error, or may contain the raw error message itself (such\nas an exception). In perl exception may be blessed objects, as such the raw data for this\nfacet may contain nested items which are blessed.\n\nNot all errors are considered fatal, there is a \"fail\" field that must be set for an error\nto cause the test to fail.\n\nNote: This facet is unique in that the field name is 'errors' while the package is 'Error'.\nThis is because this is the only facet type that is both a list, and has a name where the\nplural is not the same as the singular. This may cause some confusion, but I feel it will be\nless confusing than the alternative.\n\ninfo => [{...}, ...]\nTest2::EventFacet::Info\n\nThe 'info' facet is a list instead of a single item, any quantity of extra information can\nbe attached to an event. Some information may be critical diagnostics, others may be simply\ncommentary in nature, this is determined by the \"debug\" flag.\n\nFor this facet the \"details\" flag is the info itself. This info may be a string, or it may\nbe a data structure to display. This is one of the few facet types that may contain blessed\nitems.\n\nLEGACY API\n$bool = $e->causesfail\nReturns true if this event should result in a test failure. In general this should be false.\n\n$bool = $e->incrementscount\nShould be true if this event should result in a test count increment.\n\n$e->callback($hub)\nIf your event needs to have extra effects on the Test2::Hub you can override this method.\n\nThis is called BEFORE your event is passed to the formatter.\n\n$num = $e->nested\nIf this event is nested inside of other events, this should be the depth of nesting. (This\nis mainly for subtests)\n\n$bool = $e->global\nSet this to true if your event is global, that is ALL threads and processes should see it no\nmatter when or where it is generated. This is not a common thing to want, it is used by\nbail-out and skipall to end testing.\n\n$code = $e->terminate\nThis is called AFTER your event has been passed to the formatter. This should normally\nreturn undef, only change this if your event should cause the test to exit immediately.\n\nIf you want this event to cause the test to exit you should return the exit code here. Exit\ncode of 0 means exit success, any other integer means exit with failure.\n\nThis is used by Test2::Event::Plan to exit 0 when the plan is 'skipall'. This is also used\nby Test2::Event:Bail to force the test to exit with a failure.\n\nThis is called after the event has been sent to the formatter in order to ensure the event\nis seen and understood.\n\n$msg = $e->summary\nThis is intended to be a human readable summary of the event. This should ideally only be\none line long, but you can use multiple lines if necessary. This is intended for human\nconsumption. You do not need to make it easy for machines to understand.\n\nThe default is to simply return the event package name.\n\n($count, $directive, $reason) = $e->setsplan()\nCheck if this event sets the testing plan. It will return an empty list if it does not. If\nit does set the plan it will return a list of 1 to 3 items in order: Expected Test Count,\nTest Directive, Reason for directive.\n\n$bool = $e->diagnostics\nTrue if the event contains diagnostics info. This is useful because a non-verbose harness\nmay choose to hide events that are not in this category. Some formatters may choose to send\nthese to STDERR instead of STDOUT to ensure they are seen.\n\n$bool = $e->nodisplay\nFalse by default. This will return true on events that should not be displayed by\nformatters.\n\n$id = $e->insubtest\nIf the event is inside a subtest this should have the subtest ID.\n\n$id = $e->subtestid\nIf the event is a final subtest event, this should contain the subtest ID.\n",
                "subsections": []
            },
            "THIRD PARTY META-DATA": {
                "content": "This object consumes Test2::Util::ExternalMeta which provides a consistent way for you to attach\nmeta-data to instances of this class. This is useful for tools, plugins, and other extensions.\n",
                "subsections": []
            },
            "SOURCE": {
                "content": "The source code repository for Test2 can be found at http://github.com/Test-More/test-more/.\n",
                "subsections": []
            },
            "MAINTAINERS": {
                "content": "Chad Granum <exodist@cpan.org>\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "Chad Granum <exodist@cpan.org>\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright 2020 Chad Granum <exodist@cpan.org>.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nSee http://dev.perl.org/licenses/\n",
                "subsections": []
            }
        }
    }
}