<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Test2::Event::V2;
use strict;
use warnings;

our $VERSION = '1.302194';

use Scalar::Util qw/reftype/;
use Carp qw/croak/;

BEGIN { require Test2::Event; our @ISA = qw(Test2::Event) }

use Test2::Util::Facets2Legacy qw{
    causes_fail diagnostics global increments_count no_display sets_plan
    subtest_id summary terminate
};

use Test2::Util::HashBase qw/-about/;

sub non_facet_keys {
    return (
        +UUID,
        Test2::Util::ExternalMeta::META_KEY(),
    );
}

sub init {
    my $self = shift;

    my $uuid;
    if ($uuid = $self-&gt;{+UUID}) {
        croak "uuid '$uuid' passed to constructor, but uuid '$self-&gt;{+ABOUT}-&gt;{uuid}' is already set in the 'about' facet"
            if $self-&gt;{+ABOUT}-&gt;{uuid} &amp;&amp; $self-&gt;{+ABOUT}-&gt;{uuid} ne $uuid;

        $self-&gt;{+ABOUT}-&gt;{uuid} = $uuid;
    }
    elsif ($self-&gt;{+ABOUT} &amp;&amp; $self-&gt;{+ABOUT}-&gt;{uuid}) {
        $uuid = $self-&gt;{+ABOUT}-&gt;{uuid};
        $self-&gt;SUPER::set_uuid($uuid);
    }

    # Clone the trace, make sure it is blessed
    if (my $trace = $self-&gt;{+TRACE}) {
        $self-&gt;{+TRACE} = Test2::EventFacet::Trace-&gt;new(%$trace);
    }
}

sub set_uuid {
    my $self = shift;
    my ($uuid) = @_;
    $self-&gt;{+ABOUT}-&gt;{uuid} = $uuid;
    $self-&gt;SUPER::set_uuid($uuid);
}

sub facet_data {
    my $self = shift;
    my $f = { %{$self} };

    delete $f-&gt;{$_} for $self-&gt;non_facet_keys;

    my %out;
    for my $k (keys %$f) {
        next if substr($k, 0, 1) eq '_';

        my $data = $f-&gt;{$k} or next; # Key is there, but no facet
        my $is_list = 'ARRAY' eq (reftype($data) || '');
        $out{$k} = $is_list ? [ map { {%{$_}} } @$data ] : {%$data};
    }

    if (my $meta = $self-&gt;meta_facet_data) {
        $out{meta} = {%$meta, %{$out{meta} || {}}};
    }

    return \%out;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Test2::Event::V2 - Second generation event.

=head1 DESCRIPTION

This is the event type that should be used instead of L&lt;Test2::Event&gt; or its
legacy subclasses.

=head1 SYNOPSIS

=head2 USING A CONTEXT

    use Test2::API qw/context/;

    sub my_tool {
        my $ctx = context();

        my $event = $ctx-&gt;send_ev2(info =&gt; [{tag =&gt; 'NOTE', details =&gt; "This is a note"}]);

        $ctx-&gt;release;

        return $event;
    }

=head2 USING THE CONSTRUCTOR

    use Test2::Event::V2;

    my $e = Test2::Event::V2-&gt;new(
        trace =&gt; {frame =&gt; [$PKG, $FILE, $LINE, $SUBNAME]},
        info  =&gt; [{tag =&gt; 'NOTE', details =&gt; "This is a note"}],
    );

=head1 METHODS

This class inherits from L&lt;Test2::Event&gt;.

=over 4

=item $fd = $e-&gt;facet_data()

This will return a hashref of facet data. Each facet hash will be a shallow
copy of the original.

=item $about = $e-&gt;about()

This will return the 'about' facet hashref.

B&lt;NOTE:&gt; This will return the internal hashref, not a copy.

=item $trace = $e-&gt;trace()

This will return the 'trace' facet, normally blessed (but this is not enforced
when the trace is set using C&lt;set_trace()&gt;.

B&lt;NOTE:&gt; This will return the internal trace, not a copy.

=back

=head2 MUTATION

=over 4

=item $e-&gt;add_amnesty({...})

Inherited from L&lt;Test2::Event&gt;. This can be used to add 'amnesty' facets to an
existing event. Each new item is added to the B&lt;END&gt; of the list.

B&lt;NOTE:&gt; Items B&lt;ARE&gt; blessed when added.

=item $e-&gt;add_hub({...})

Inherited from L&lt;Test2::Event&gt;. This is used by hubs to stamp events as they
pass through. New items are added to the B&lt;START&gt; of the list.

B&lt;NOTE:&gt; Items B&lt;ARE NOT&gt; blessed when added.

=item $e-&gt;set_uuid($UUID)

Inherited from L&lt;Test2::Event&gt;, overridden to also vivify/mutate the 'about'
facet.

=item $e-&gt;set_trace($trace)

Inherited from L&lt;Test2::Event&gt; which allows you to change the trace.

B&lt;Note:&gt; This method does not bless/clone the trace for you. Many things will
expect the trace to be blessed, so you should probably do that.

=back

=head2 LEGACY SUPPORT METHODS

These are all imported from L&lt;Test2::Util::Facets2Legacy&gt;, see that module or
L&lt;Test2::Event&gt; for documentation on what they do.

=over 4

=item causes_fail

=item diagnostics

=item global

=item increments_count

=item no_display

=item sets_plan

=item subtest_id

=item summary

=item terminate

=back

=head1 THIRD PARTY META-DATA

This object consumes L&lt;Test2::Util::ExternalMeta&gt; which provides a consistent
way for you to attach meta-data to instances of this class. This is useful for
tools, plugins, and other extensions.

=head1 SOURCE

The source code repository for Test2 can be found at
F&lt;http://github.com/Test-More/test-more/&gt;.

=head1 MAINTAINERS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 AUTHORS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 COPYRIGHT

Copyright 2020 Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

See F&lt;http://dev.perl.org/licenses/&gt;

=cut
</pre></body></html>