{
    "mode": "perldoc",
    "parameter": "Test2::API::InterceptResult::Event",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Test2%3A%3AAPI%3A%3AInterceptResult%3A%3AEvent/json",
    "generated": "2026-06-13T01:26:04Z",
    "synopsis": "use Test2::V0;\nuse Test2::API qw/intercept/;\nmy $events = intercept {\nok(1, \"A passing assertion\");\nplan(1);\n};\n# This will convert all events into instances of\n# Test2::API::InterceptResult::Event. Until we do this they are the\n# original Test::Event::* instances\n$events->upgrade(inplace => 1);\n# Now we can get individual events in this form\nmy $assert = $events->[0];\nmy $plan   = $events->[1];\n# Or we can operate on all events at once:\nmy $flattened = $events->flatten;\nis(\n$flattened,\n[\n{\ncausesfailure => 0,\nname => 'A passing assertion',\npass => 1,\ntracefile => 'xxx.t',\ntraceline => 5,\n},\n{\ncausesfailure => 0,\nplan => 1,\ntracefile => 'xxx.t',\ntraceline => 6,\n},\n],\n\"Flattened both events and returned an arrayref of the results\n);",
    "sections": {
        "NAME": {
            "content": "Test2::API::InterceptResult::Event - Representation of an event for use in testing other test\ntools.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"intercept { ... }\" from Test2::API returns an instance of Test2::API::InterceptResult which is\na blessed arrayref of Test2::API::InterceptResult::Event objects.\n\nThis POD documents the methods of these events, which are mainly provided for you to use when\ntesting your test tools.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Test2::V0;\nuse Test2::API qw/intercept/;\n\nmy $events = intercept {\nok(1, \"A passing assertion\");\nplan(1);\n};\n\n# This will convert all events into instances of\n# Test2::API::InterceptResult::Event. Until we do this they are the\n# original Test::Event::* instances\n$events->upgrade(inplace => 1);\n\n# Now we can get individual events in this form\nmy $assert = $events->[0];\nmy $plan   = $events->[1];\n\n# Or we can operate on all events at once:\nmy $flattened = $events->flatten;\nis(\n$flattened,\n[\n{\ncausesfailure => 0,\n\nname => 'A passing assertion',\npass => 1,\n\ntracefile => 'xxx.t',\ntraceline => 5,\n},\n{\ncausesfailure => 0,\n\nplan => 1,\n\ntracefile => 'xxx.t',\ntraceline => 6,\n},\n],\n\"Flattened both events and returned an arrayref of the results\n);\n",
            "subsections": []
        },
        "METHODS": {
            "content": "!!! IMPORTANT NOTES ON DESIGN !!!\nPlease pay attention to what these return, many return a scalar when applicable or an empty list\nwhen not (as opposed to undef). Many also always return a list of 0 or more items. Some always\nreturn a scalar. Note that none of the methods care about context, their behavior is consistent\nregardless of scalar, list, or void context.\n\nThis was done because this class was specifically designed to be used in a list and generate\nmore lists in bulk operations. Sometimes in a map you want nothing to show up for the event, and\nyou do not want an undef in its place. In general single event instances are not going to be\nused alone, though that is allowed.\n\nAs a general rule any method prefixed with \"the\" implies the event should have exactly 1 of the\nspecified item, and and exception will be thrown if there are 0, or more than 1 of the item.\n\nATTRIBUTES\n$hashref = $event->facetdata\nThis will return the facet data hashref, which is all Test2 cares about for any given event.\n\n$class = $event->resultclass\nThis is normally Test2::API::InterceptResult. This is set at construction so that subtest\nresults can be turned into instances of it on demand.\n\nDUPLICATION\n$copy = $event->clone\nCreate a deep copy of the event. Modifying either event will not effect the other.\n\nCONDENSED MULTI-FACET DATA\n$bool = $event->causesfailure\n$bool = $event->causesfail\nThese are both aliases of the same functionality.\n\nThis will always return either a true value, or a false value. This never returns a list.\n\nThis method may be relatively slow (still super fast) because it determines pass or fail by\ncreating an instance of Test2::Hub and asking it to process the event, and then asks the hub\nfor its pass/fail state. This is slower than bulding in logic to do the check, but it is\nmore reliable as it will always tell you what the hub thinks, so the logic will never be out\nof date relative to the Test2 logic that actually cares.\n\nSTRINGOREMPTYLIST = $event->brief\nNot all events have a brief, some events are not rendered by the formatter, others have no\n\"brief\" data worth seeing. When this is the case an empty list is returned. This is done\nintentionally so it can be used in a map operation without having \"undef\" being included in\nthe result.\n\nWhen a brief can be generated it is always a single 1-line string, and is returned as-is,\nnot in a list.\n\nPossible briefs:\n\n# From control facets\n\"BAILED OUT\"\n\"BAILED OUT: $why\"\n\n# From error facets\n\"ERROR\"\n\"ERROR: $message\"\n\"ERROR: $partialmessage [...]\"\n\"ERRORS: $firsterrormessage [...]\"\n\n# From assert facets\n\"PASS\"\n\"FAIL\"\n\"PASS with amnesty\"\n\"FAIL with amnesty\"\n\n# From plan facets\n\"PLAN $count\"\n\"NO PLAN\"\n\"SKIP ALL\"\n\"SKIP ALL: $why\"\n\nNote that only the first applicable brief is returned. This is essnetially a poor-mans TAP\nthat only includes facets that could (but not necessarily do) cause a failure.\n\n$hashref = $event->flatten\n$hashref = $event->flatten(includesubevents => 1)\nThis ALWAYS returns a hashref. This puts all the most useful data for the most interesting\nfacets into a single hashref for easy validation.\n\nIf there are no meaningful facets this will return an empty hashref.\n\nIf given the 'includesubevents' parameter it will also include subtest data:\n\nHere is a list of EVERY possible field. If a field is not applicable it will not be present.\n\nalways present\ncausesfailure => 1,    # Always present\n\nPresent if the event has a trace facet\ntraceline    => 42,\ntracefile    => 'Foo/Bar.pm',\ntracedetails => 'Extra trace details',    # usually not present\n\nIf an assertion is present\npass => 0,\nname => \"1 + 1 = 2, so math works\",\n\nIf a plan is present:\nplan => $countorSKIPALLorNOPLAN,\n\nIf amnesty facets are present\nYou get an array for each type that is present.\n\ntodo => [    # Yes you could be under multiple todos, this will list them all.\n\"I will fix this later\",\n\"I promise to fix these\",\n],\n\nskip => [\"This will format the main drive, do not run\"],\n\n... => [\"Other amnesty\"]\n\nIf Info (note/diag) facets are present\nYou get an arrayref for any that are present, the key is not defined if they are not\npresent.\n\ndiag => [\n\"Test failed at Foo/Bar.pm line 42\",\n\"You forgot to tie your boots\",\n],\n\nnote => [\"Your boots are red\"],\n\n...  => [\"Other info\"],\n\nIf error facets are present\nAlways an arrayref\n\nerror => [\n\"non fatal error (does not cause test failure, just an FYI\",\n\"FATAL: This is a fatal error (causes failure)\",\n],\n\n# Errors can have alternative tags, but in practice are always 'error',\n# listing this for completeness.\n... => [ ... ]\n\nPresent if the event is a subtest\nsubtest => {\ncount      => 2,    # Number of assertions made\nfailed     => 1,    # Number of test failures seen\nispassing => 0,    # Boolean, true if the test would be passing\n# after the events are processed.\n\nplan         => 2,  # Plan, either a number, undef, 'SKIP', or 'NO PLAN'\nfollowsplan => 1,  # True if there is a plan and it was followed.\n# False if the plan and assertions did not\n# match, undef if no plan was present in the\n# event list.\n\nbailedout => \"foo\",    # if there was a bail-out in the\n# events in this will be a string explaining\n# why there was a bailout, if no reason was\n# given this will simply be set to true (1).\n\nskipreason => \"foo\",   # If there was a skipall this will give the\n# reason.\n},\n\nif \"(includesubtest => 1)\" was provided as a parameter then the following will be\nincluded. This is the result of turning all subtest child events into an\nTest2::API::InterceptResult instance and calling the \"flatten\" method on it.\n\nsubevents => Test2::API::InterceptResult->new(@childevents)->flatten(...),\n\nIf a bail-out is being requested\nIf no reason was given this will be set to 1.\n\nbailedout => \"reason\",\n\n$hashref = $event->summary()\nThis returns a limited summary. See \"flatten()\", which is usually a better option.\n\n{\nbrief => $event->brief || '',\n\ncausesfailure => $event->causesfailure,\n\ntraceline    => $event->traceline,\ntracefile    => $event->tracefile,\ntracetool    => $event->tracesubname,\ntracedetails => $event->tracedetails,\n\nfacets => [ sort keys(%{$event->{+FACETDATA}}) ],\n}\n\nDIRECT ARBITRARY FACET ACCESS\n@listoffacets = $event->facet($name)\nThis always returns a list of 0 or more items. This fetches the facet instances from the\nevent. For facets like 'assert' this will always return 0 or 1 item. For events like 'info'\n(diags, notes) this will return 0 or more instances, once for each instance of the facet.\n\nThese will be blessed into the proper Test2::EventFacet subclass. If no subclass can be\nfound it will be blessed as an Test2::API::InterceptResult::Facet generic facet class.\n\n$undeforfacet = $event->thefacet($name)\nIf you know you will have exactly 1 instance of a facet you can call this.\n\nIf you are correct and there is exactly one instance of the facet it will always return the\nhashref.\n\nIf there are 0 instances of the facet this will reutrn undef, not an empty list.\n\nIf there are more than 1 instance this will throw an exception because your assumption was\nincorrect.\n\nTRACE FACET\n@listoffacets = $event->trace\nTODO\n\n$undeforhashref = $event->thetrace\nThis returns the trace hashref, or undef if it is not present.\n\n$undeforarrayref = $event->frame\nIf a trace is present, and has a caller frame, this will be an arrayref:\n\n[$package, $file, $line, $subname]\n\nIf the trace is not present, or has no caller frame this will return undef.\n\n$undeforstring = $event->tracedetails\nThis is usually undef, but occasionally has a string that overrides the file/line number\ndebugging a trace usually provides on test failure.\n\n$undeforstring = $event->tracepackage\nSame as \"(caller())[0]\", the first element of the trace frame.\n\nWill be undef if not present.\n\n$undeforstring = $event->tracefile\nSame as \"(caller())[1]\", the second element of the trace frame.\n\nWill be undef if not present.\n\n$undeforinteger = $event->traceline\nSame as \"(caller())[2]\", the third element of the trace frame.\n\nWill be undef if not present.\n\n$undeforstring = $event->tracesubname\n$undeforstring = $event->tracetool\nAliases for the same thing\n\nSame as \"(caller($level))[4]\", the fourth element of the trace frame.\n\nWill be undef if not present.\n\n$undeforstring = $event->tracesignature\nA string that is a unique signature for the trace. If a single context generates multiple\nevents they will all have the same signature. This can be used to tie assertions and\ndiagnostics sent as seperate events together after the fact.\n\nASSERT FACET\n$bool = $event->hasassert\nReturns true if the event has an assert facet, false if it does not.\n\n$undeforhashref = $event->theassert\nReturns the assert facet if present, undef if it is not.\n\n@listoffacets = $event->assert\nTODO\n\nEMPTYLISTORSTRING = $event->assertbrief\nReturns a string giving a brief of the assertion if an assertion is present. Returns an\nempty list if no assertion is present.\n\nSUBTESTS (PARENT FACET)\n$bool = $event->hassubtest\nTrue if a subetest is present in this event.\n\n$undeforhashref = $event->thesubtest\nGet the one subtest if present, otherwise undef.\n\n@listoffacets = $event->subtest\nTODO\n\nEMPTYLISTOROBJECT = $event->subtestresult\nReturns an empty list if there is no subtest.\n\nGet an instance of Test2::API::InterceptResult representing the subtest.\n\nCONTROL FACET (BAILOUT, ENCODING)\n$bool = $event->hasbailout\nTrue if there was a bailout\n\n$undefhashref = $event->thebailout\nReturn the control facet if it requested a bailout.\n\nEMPTYLISTORHASHREF = $event->bailout\nGet a list of 0 or 1 hashrefs. The hashref will be the control facet if a bail-out was\nrequested.\n\nEMPTYLISTORSTRING = $event->bailoutbrief\nGet the brief of the balout if present.\n\nEMPTYLISTORSTRING = $event->bailoutreason\nGet the reason for the bailout, an empty string if no reason was provided, or an empty list\nif there was no bailout.\n\nPLAN FACET\nTODO\n\n$bool = $event->hasplan\n$undeforhashref = $event->theplan\n@listifhashrefs = $event->plan\nEMPTYLISTORSTRING $event->planbrief\n\nAMNESTY FACET (TODO AND SKIP)\nTODO\n\n$event->hasamnesty\n$event->theamnesty\n$event->amnesty\n$event->amnestyreasons\n$event->hastodos\n$event->todos\n$event->todoreasons\n$event->hasskips\n$event->skips\n$event->skipreasons\n$event->hasotheramnesty\n$event->otheramnesty\n$event->otheramnestyreasons\n\nERROR FACET (CAPTURED EXCEPTIONS)\nTODO\n\n$event->haserrors\n$event->theerrors\n$event->errors\n$event->errormessages\n$event->errorbrief\n\nINFO FACET (DIAG, NOTE)\nTODO\n\n$event->hasinfo\n$event->theinfo\n$event->info\n$event->infomessages\n$event->hasdiags\n$event->diags\n$event->diagmessages\n$event->hasnotes\n$event->notes\n$event->notemessages\n$event->hasotherinfo\n$event->otherinfo\n$event->otherinfomessages\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": []
        }
    },
    "summary": "Test2::API::InterceptResult::Event - Representation of an event for use in testing other test tools.",
    "flags": [],
    "examples": [],
    "see_also": []
}