1 package Test2::Event::V2;
5 our $VERSION = '1.302182';
7 use Scalar::Util qw/reftype/;
10 BEGIN { require Test2::Event; our @ISA = qw(Test2::Event) }
12 use Test2::Util::Facets2Legacy qw{
13 causes_fail diagnostics global increments_count no_display sets_plan
14 subtest_id summary terminate
17 use Test2::Util::HashBase qw/-about/;
22 Test2::Util::ExternalMeta::META_KEY(),
30 if ($uuid = $self->{+UUID}) {
31 croak "uuid '$uuid' passed to constructor, but uuid '$self->{+ABOUT}->{uuid}' is already set in the 'about' facet"
32 if $self->{+ABOUT}->{uuid} && $self->{+ABOUT}->{uuid} ne $uuid;
34 $self->{+ABOUT}->{uuid} = $uuid;
36 elsif ($self->{+ABOUT} && $self->{+ABOUT}->{uuid}) {
37 $uuid = $self->{+ABOUT}->{uuid};
38 $self->SUPER::set_uuid($uuid);
41 # Clone the trace, make sure it is blessed
42 if (my $trace = $self->{+TRACE}) {
43 $self->{+TRACE} = Test2::EventFacet::Trace->new(%$trace);
50 $self->{+ABOUT}->{uuid} = $uuid;
51 $self->SUPER::set_uuid($uuid);
58 delete $f->{$_} for $self->non_facet_keys;
61 for my $k (keys %$f) {
62 next if substr($k, 0, 1) eq '_';
64 my $data = $f->{$k} or next; # Key is there, but no facet
65 my $is_list = 'ARRAY' eq (reftype($data) || '');
66 $out{$k} = $is_list ? [ map { {%{$_}} } @$data ] : {%$data};
69 if (my $meta = $self->meta_facet_data) {
70 $out{meta} = {%$meta, %{$out{meta} || {}}};
86 Test2::Event::V2 - Second generation event.
90 This is the event type that should be used instead of L<Test2::Event> or its
95 =head2 USING A CONTEXT
97 use Test2::API qw/context/;
102 my $event = $ctx->send_ev2(info => [{tag => 'NOTE', details => "This is a note"}]);
109 =head2 USING THE CONSTRUCTOR
111 use Test2::Event::V2;
113 my $e = Test2::Event::V2->new(
114 trace => {frame => [$PKG, $FILE, $LINE, $SUBNAME]},
115 info => [{tag => 'NOTE', details => "This is a note"}],
120 This class inherits from L<Test2::Event>.
124 =item $fd = $e->facet_data()
126 This will return a hashref of facet data. Each facet hash will be a shallow
127 copy of the original.
129 =item $about = $e->about()
131 This will return the 'about' facet hashref.
133 B<NOTE:> This will return the internal hashref, not a copy.
135 =item $trace = $e->trace()
137 This will return the 'trace' facet, normally blessed (but this is not enforced
138 when the trace is set using C<set_trace()>.
140 B<NOTE:> This will return the internal trace, not a copy.
148 =item $e->add_amnesty({...})
150 Inherited from L<Test2::Event>. This can be used to add 'amnesty' facets to an
151 existing event. Each new item is added to the B<END> of the list.
153 B<NOTE:> Items B<ARE> blessed when added.
155 =item $e->add_hub({...})
157 Inherited from L<Test2::Event>. This is used by hubs to stamp events as they
158 pass through. New items are added to the B<START> of the list.
160 B<NOTE:> Items B<ARE NOT> blessed when added.
162 =item $e->set_uuid($UUID)
164 Inherited from L<Test2::Event>, overridden to also vivify/mutate the 'about'
167 =item $e->set_trace($trace)
169 Inherited from L<Test2::Event> which allows you to change the trace.
171 B<Note:> This method does not bless/clone the trace for you. Many things will
172 expect the trace to be blessed, so you should probably do that.
176 =head2 LEGACY SUPPORT METHODS
178 These are all imported from L<Test2::Util::Facets2Legacy>, see that module or
179 L<Test2::Event> for documentation on what they do.
189 =item increments_count
203 =head1 THIRD PARTY META-DATA
205 This object consumes L<Test2::Util::ExternalMeta> which provides a consistent
206 way for you to attach meta-data to instances of this class. This is useful for
207 tools, plugins, and other extensions.
211 The source code repository for Test2 can be found at
212 F<http://github.com/Test-More/test-more/>.
218 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
226 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
232 Copyright 2020 Chad Granum E<lt>exodist@cpan.orgE<gt>.
234 This program is free software; you can redistribute it and/or
235 modify it under the same terms as Perl itself.
237 See F<http://dev.perl.org/licenses/>