NAME
Net::Nostr::Label - NIP-32 Labeling
SYNOPSIS
use Net::Nostr::Label;
# Create a kind 1985 label event
my $event = Net::Nostr::Label->label(
pubkey => $pubkey,
namespace => 'com.example.ontology',
labels => ['VI-hum'],
targets => [['p', $target_pk, $relay]],
content => 'Explanation of the label',
);
# Build tags for self-reporting on any event
my $L = Net::Nostr::Label->namespace_tag('ISO-639-1');
my $l = Net::Nostr::Label->label_tag('en', 'ISO-639-1');
# Parse labels from an event
my $info = Net::Nostr::Label->from_event($event);
my @namespaces = @{$info->namespaces};
my @labels = @{$info->labels};
my @en_labels = $info->labels_for('ISO-639-1');
# Check for a specific label
if ($info->has_label('MIT', 'license')) { ... }
# Build a subscription filter
my $filter = Net::Nostr::Label->label_filter(
namespace => 'license',
labels => ['MIT'],
);
CONSTRUCTOR
new
my $label = Net::Nostr::Label->new(
namespaces => ['ISO-639-1'],
labels => [['en', 'ISO-639-1']],
targets => [['e', $event_id, $relay]],
);
Creates a new label object. namespaces, labels, and targets all default to []. Croaks on unknown arguments.
DESCRIPTION
Implements NIP-32 (Labeling). Provides methods to create kind 1985 label events, build L/l tags for self-reporting, parse labels from events, and build subscription filters.
label
my $event = Net::Nostr::Label->label(
pubkey => $pubkey,
namespace => 'license',
labels => ['MIT'],
targets => [['e', $event_id, $relay]],
content => 'optional explanation',
);
Creates a kind 1985 label event. namespace is optional; if omitted, the ugc namespace is implied and no L tag is emitted. targets must include at least one e, p, a, r, or t tag.
namespace_tag
my $tag = Net::Nostr::Label->namespace_tag('ISO-639-1');
# ['L', 'ISO-639-1']
Returns an L tag arrayref. Use when building tags for self-reporting on non-1985 events.
label_tag
my $tag = Net::Nostr::Label->label_tag('en', 'ISO-639-1');
# ['l', 'en', 'ISO-639-1']
my $tag = Net::Nostr::Label->label_tag('spam');
# ['l', 'spam']
Returns an l tag arrayref. The namespace mark is optional; if omitted, ugc is implied.
from_event
my $info = Net::Nostr::Label->from_event($event);
my @ns = @{$info->namespaces}; # L tag values
my @labels = @{$info->labels}; # [value, mark?] pairs
my @targets = @{$info->targets}; # target tags
Parses label information from any event (kind 1985 or self-reported). Returns a Net::Nostr::Label object with accessors for namespaces, labels, and targets.
labels_for
my @values = $info->labels_for('ISO-639-1');
Returns label values for a specific namespace.
has_label
if ($info->has_label('MIT', 'license')) { ... }
if ($info->has_label('spam')) { ... }
Returns true if the label set contains the given value, optionally within the specified namespace.
validate
Net::Nostr::Label->validate($event);
Validates a kind 1985 label event. Croaks if the event is not kind 1985, has no target tags, or has l tag marks that don't match any L namespace.
label_filter
my $filter = Net::Nostr::Label->label_filter(
namespace => 'license',
labels => ['MIT', 'GPL'],
authors => [$pubkey],
);
Returns a subscription filter hashref for querying label events. All parameters are optional.
ACCESSORS
namespaces
Arrayref of L tag values (namespace strings).
labels
Arrayref of [value, namespace?] pairs from l tags.
targets
Arrayref of target tags (e, p, a, r, or t tags).