Test2::Util::ExternalMeta โ Allow third party tools to safely attach metaโdata to your instances.
| Use Case | Command | Description |
|---|---|---|
| Get meta value | $obj->meta($key) | Return value for $key, optionally setting a default if missing. |
| Get meta value (no default) | $obj->get_meta($key) | Return value for $key, without default overhead. |
| Set meta value | $obj->set_meta($key, $val) | Store a value under $key. |
| Delete meta value | $obj->delete_meta($key) | Remove the entry for $key and return the old value. |
This package lets you define a clear, and consistent way to allow third party tools to attach metaโdata to your instances. If your object consumes this package, and imports its methods, then third party metaโdata has a safe place to live.
package My::Object;
use strict;
use warnings;
use Test2::Util::ExternalMeta qw/meta get_meta set_meta delete_meta/;
...
Now to use it:
my $inst = My::Object->new;
$inst->set_meta(foo => 'bar');
my $val = $inst->get_meta('foo');
This package assumes your instances are blessed hashrefs; it will not work if that is not true. It will store all metaโdata in the _meta key on your objectโs hash. If your object makes use of the _meta key in its underlying hash, then there is a conflict and you cannot use this package.
$val = $obj->meta($key)$val = $obj->meta($key, $default)$key. Normally returns undef when no value exists, but you can specify a $default value to set when no value is already set.$val = $obj->get_meta($key)$key. This does not have the $default overhead that meta() does.$val = $obj->delete_meta($key)$key. The old $val will be returned.$obj->set_meta($key, $val)$key.Meta keys must be defined, and must be true when used as a boolean. Keys may not be references. You are free to stringify a reference $ref for use as a key, but this package will not stringify it for you.
The source code repository for Test2 can be found at http://github.com/Test-More/test-more/.
Chad Granum <exodist AT cpan.org>
Chad Granum <exodist AT cpan.org>
Copyright 2020 Chad Granum <exodist AT cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-09 22:18 @2600:1f28:365:80b0:35e2:9369:6b76:3018
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)