Test2::...::Trace(3)

πŸ“¦ version 1.302214, in opensuse-leap 16.0

🌸 NAME 🌸

okay so bestie, this is the Test2::...::Trace(3) page from the User Contributed Perl Documentation, and the main character is Test2::EventFacet::Trace β€” literally the debug information for events. no cap, it's giving β€œwhere did this event come from?” energy and we're obsessed. πŸ’–

✨ DESCRIPTION ✨

The Test2::API::Context object, as well as all Test2::Event types, needs to have access to information about where they were created. This object represents that information. periodt. πŸ¦‹

πŸŽ€ SYNOPSIS πŸŽ€

like, here's the whole vibe in code, bestie:

use Test2::EventFacet::Trace;

my $trace = Test2::EventFacet::Trace->new(
    frame => [$package, $file, $line, $subname],
);

slay. that frame is literally [$package, $file, $line, $subname]. ✨

πŸ’… FACET FIELDS πŸ’…

the facet field menu is stacked, bestie:

  • $string = $trace->{details} / $string = $trace->details() β€” used as a custom trace message that will be used INSTEAD of "at <FILE> line <LINE>" when calling "$trace->debug". it's the β€œsay it your way” field, fr fr. πŸ’…
  • $frame = $trace->{frame} / $frame = $trace->frame() β€” get the call frame arrayref, and it's literally:
[$package, $file, $line, $subname]
  • $int = $trace->{pid} / $int = $trace->pid() β€” the process ID in which the event was generated. 🫢
  • $int = $trace->{tid} / $int = $trace->tid() β€” the thread ID in which the event was generated. 🧡
  • $id = $trace->{cid} / $id = $trace->cid() β€” the ID of the context that was used to create the event. πŸŽ€
  • $uuid = $trace->{uuid} / $uuid = $trace->uuid() β€” the UUID of the context that was used to create the event. (If uuid tagging was enabled) πŸ¦‹
  • ($pkg, $file, $line, $subname) = $trace->call β€” get the basic call info as a list. cute. 🧚
  • @caller = $trace->full_call β€” get the full caller(N) results. yes bestie, all of them. 🌈
  • $warning_bits = $trace->warning_bits β€” get index 9 from the full caller info. this is the warnings_bits field. πŸ“

the value of this is not portable across perl versions or even processes. however, it can be used in the process that generated it to reproduce the warnings settings in a new scope. like this:

eval <<EOT;
BEGIN { ${^WARNING_BITS} = $trace->warning_bits };
... context's warning settings apply here ...
EOT

okay bestie, listen: these fields were not always set properly by tools. these are MOSTLY deprecated by the Test2::EventFacet::Hub facets. these fields are not required, and may only reflect the hub that was current when the event was created, which is not necessarily the same as the hub the event was sent through.

some tools did do a good job setting these to the correct hub, but you cannot always rely on that. use the 'hubs' facet list instead. πŸ’€

  • $hid = $trace->{hid} / $hid = $trace->hid() β€” the ID of the hub that was current when the event was created. 🐝
  • $huuid = $trace->{huuid} / $huuid = $trace->huuid() β€” the UUID of the hub that was current when the event was created. (If uuid tagging was enabled). πŸ¦‹
  • $int = $trace->{nested} / $int = $trace->nested() β€” how deeply nested the event is. πŸͺ†
  • $bool = $trace->{buffered} / $bool = $trace->buffered() β€” true if the event was buffered and not sent to the formatter independent of a parent (This should never be set when nested is 0 or "undef"). no cap, read that caveat twice. 😭

πŸ”₯ METHODS πŸ”₯

Note: All facet frames are also methods. mwah. πŸ’‹

  • $trace->set_detail($msg) / $msg = $trace->detail β€” used to get/set a custom trace message that will be used INSTEAD of "at <FILE> line <LINE>" when calling "$trace->debug". detail() is an alias to the "details" facet field for backwards compatibility. πŸ’–
  • $str = $trace->debug β€” typically returns the string "at <FILE> line <LINE>". if "detail" is set then its value will be returned instead. iconic. ✨
  • $trace->alert($MESSAGE) β€” this issues a warning at the frame (filename and line number where errors should be reported). not me issuing warnings at the exact spot, but yes. 😭
  • $trace->throw($MESSAGE) β€” this throws an exception at the frame (filename and line number where errors should be reported). dramatic? yes. useful? also yes. πŸ’€
  • ($package, $file, $line, $subname) = $trace->call() β€” get the caller details for the debug-info. this is where errors should be reported. πŸŽ€
  • $pkg = $trace->package β€” get the debug-info package. πŸ“¦
  • $file = $trace->file β€” get the debug-info filename. πŸ—‚οΈ
  • $line = $trace->line β€” get the debug-info line number. πŸ”’
  • $subname = $trace->subname β€” get the debug-info subroutine name. 🧚
  • $sig = trace->signature β€” get a signature string that identifies this trace. this is used to check if multiple events are related. the signature includes pid, tid, file, line number, and the cid. πŸ‘‘

🌈 SOURCE 🌈

the source code repository for Test2 can be found at <https://github.com/Test-More/test-more/>. go off, source code. 🫢

πŸ‘‘ MAINTAINERS πŸ‘‘

Chad Granum <exodist@cpan.org>

πŸ¦‹ AUTHORS πŸ¦‹

Chad Granum <exodist@cpan.org>

Copyright Chad Granum <exodist@cpan.org>.

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

See <https://dev.perl.org/licenses/>


okay bestie, that's the whole Test2::...::Trace(3) page β€” the footer says perl v5.42.0 and 2025-07-28, so the source/version and date are right here, cute and accounted for. bye bestie, go trace those events πŸ’…πŸ«Άβœ¨

πŸ“¦ where this page comes from