NAME

At::Protocol::NSID - AT Protocol NSID Validation

SYNOPSIS

use At::Protocol::NSID qw[:all];
try {
    ensureValidNSID( 'net.users.bob.ping' );
}
catch($err) {
    ...; # do something about it
}

DESCRIPTION

Namespaced Identifiers (NSIDs) are used to reference Lexicon schemas for records, XRPC endpoints, and more.

The basic structure and semantics of an NSID are a fully-qualified hostname in Reverse Domain-Name Order, followed by a simple name. The hostname part is the domain authority, and the final segment is the name.

This package aims to validate them.

Functions

You may import functions by name or with the :all tag.

new( ... )

Verifies an NSID and creates a new object containing it.

my $nsid = At::Protocol::NSID->new( 'com.example.fooBar' );

On success, an object is returned that will stringify to the NSID itself.

parse( ... )

my $nsid = parse( 'com.example.fooBar' );

Wrapper around new(...) for the sake of compatibility.

create( ... )

my $nsid = create( 'alex.example.com' );

Parses a 'normal' (sub)domain name and creates an NSID object.

authority( )

my $auth = $nsid->authority;

Returns the domain authority of the NSID.

name( )

my $name = $nsid->name;

Returns the name from the NSID.

isValid( ... )

my $ok = isValid( 'com.exa💩ple.thing' );

Returns a boolean value indicating whether the given NSID is valid and can be parsed.

ensureValidNsid( ... )

ensureValidNsid( '.com.example.wrong' );

Validates an NSID. Throws errors on failure and returns a true value on success.

ensureValidNsidRegex( ... )

ensureValidNsidRegex( 'com.example.right' );

Validates an NSID with cursory regex provided by the AT protocol designers. Throws errors on failure and returns a true value on success.

See Also

https://atproto.com/specs/nsid

LICENSE

Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License 2. Other copyrights, terms, and conditions may apply to data transmitted through this module.

AUTHOR

Sanko Robinson <sanko@cpan.org>