Syntax(3)

πŸ“¦
version 0.13 Β· 2 versions
, in fedora 43

πŸŽ€ Syntax(3) πŸŽ€

okay bestie, so this is Syntax(3), a page from the User Contributed Perl Documentation, and it's literally all about how to speak the license-name language. pull up a chair, we're decoding ✨


✨ NAME ✨

License::Syntax β€” Coding and Decoding of License strings using SPDX and SUSE syntax. πŸ’…


🌸 VERSION 🌸

Version 0.13 β€” yes queen, we're on the glow-up release πŸ¦‹


πŸ’– SYNOPSIS πŸ’–

This implements the SUSE License Syntax. periodt.

use License::Syntax;

my $obj = new License::Syntax licensemap => 'licenselist.csv;as';
my $obj = new License::Syntax map => { 'GNU General Public License V2.0' => 'GPLv2' };
my $obj = new License::Syntax 'pathname.sqlite;table(alias,name)';
$obj->loadmap_csv($filename_csv);
$obj->loadmap_sqlite($filename_sqlite, $table_name, $alias_col, $name_col);
$obj->savemap_csv($filename_csv, scalar(localtime));
$obj->savemap_sqlite($filename_sqlite, $table_name, $alias_col, $name_col, 'TRUNCATE');
$obj->add_alias($alias, $canonical_name);
$name = $obj->canonical_name($alias, $disambiguate);
$tree = $obj->tokenize('GPLv2 & Apache 1.1; LGPLv2.1 | BSD4c<<ex(UCB); Any Noncommercial', $disambiguate);
$name = $obj->format_tokens($tree);

πŸ”₯ FUNCTIONS πŸ”₯

🫢 new

License::Syntax is an object oriented module. When you're constructing new License::Syntax objects, you can hand it a mapping table for license names. That table does double duty:

  • it's how we recognize alternate alias names for the licenses (that's the left hand side), and
  • it also defines the canonical short names of the licenses (that's the right hand side).

The mapping table gets consulted twice β€” before and after decoding the syntax. (So yes, non-terminal mappings may actually be followed. it's giving recursive, iykyk.)

You can provide that mapping table either:

  • as a CSV file of two columns. Column separator is a comma (,)
  • as a hash, or
  • as a table in an sqlite database, using the given columns as left hand side and right hand side respectively.

As an alternative to specifying a mapping with new(), or additionally on top of it, mappings can also be provided via loadmap_sqlite(), loadmap_csv(), or add_alias() methods. Earlier mappings take precedence over later mappings. so order matters, bestie, don't be chaotic about it πŸ’€

πŸ’… canonical_name

$name = $obj->canonical_name($alias);

is equivalent to

$name = $obj->format_tokens($obj->tokenize($alias));

same thing, just wrapped cute ✨

πŸŽ€ savemap_csv

$obj->savemap_csv('filename.csv', scalar(localtime));

Writes the current mapping table as a comma separated file. export your whole personality, as a CSV 🌸

🌈 set_rejects

$obj->set_rejects('REJECT', ...);

define the license names to be rejected. Per default, exactly one name, 'REJECT', is rejected. it's on the no-fly list, no cap 🚫

πŸ¦‹ add_alias

$obj->add_alias($alias,$name); $obj->add_alias(undef,$name);
$obj->add_alias('',$name);

adds $name (and optionally $alias) to the object's licensemap. Both, lower case and exact mappings are maintained. (add_url is used in loadmap_csv)

add_alias() takes care to extend to the right. That is, if its right hand side parameter is already known to be an alias, the new alias is added pointing to the old alias's canonical name (rather than to the old alias that the caller provided). the way that it just keeps going right, iconic honestly.

⚠️ CAVEAT: add_alias() does not maintain full transitivity, as it does not extend to the left. If its left hand side is already known to be a canonical name, a warning is issued, but the situation cannot be corrected, as this would require rewriting existing entries. This is non-obvious, as mappings are applied more than once during format_tokens(), so indirect mappings involving non-terminal names may or may not work. A two step mapping currently works reliably, though. so like… two hops is fine, more than that is a vibe check you might fail 😭

add_alias() does nothing, if it would directly redo an existing mapping.

See also new() for more details about mappings.

🌟 add_url

$obj->add_url($urls, $name);

Add one or multiple URLs to the canonical license name. URLs can be separated by comma or whitespace. May be called multiple times for the same name, and fills an array of urls. (add_url is used in loadmap_csv) collect links like they're stickers on your laptop πŸ“

πŸ‘‘ set_compat_class

$obj->set_compat_class($cc, $name);

Specify the compatibility class, for a canonical license name. Compatibility classes are numerical. These classes allow to derive certain compatibility issues amongst licenses. Some classes are always incompatible (even amongst themselves), other classes are always compatible, and for some other classes, compatibility is uncertain. The exact semantics are to be defined. (set_compat_class is used in loadmap_csv). it's giving "we'll figure out the lore later" πŸ’€

πŸ’œ savemap_sqlite

$obj->savemap_sqlite('filename.sqlite', 'lic_map', 'alias', 'shortname',
$trunc_flag);
# sqlite3 filename.sqlite
sqlite> select * from lic_map
alias | shortname
------|----------
...

If $trunc_flag is true and the table previously exists, the table is truncated before it is written to; otherwise new contents merges over old contents, if any. so it's either a fresh start or a stack-up, your call bestie 🫢

🌸 loadmap_sqlite

See also new() for more details about mappings.

🧚 tokenize

$tree_arr = $obj->tokenize($complex_license_expr); $tree_arr =
$obj->tokenize($complex_license_expr, 1);

Returns an array reference containing tokens and sub-arrays, describing how the $complex_license_expr is parsed. If a second parameter disambiguate is provided and is true, extra parenthesis are inserted to unambiguously show how the complex expression is interpreted. If names have been loaded with add_alias before calling tokenize, all names and aliases are recognized as one token. E.g. "GPL 2.0 or later" would be split as ["GPL 2.0", "or", "later"] otherwise. No name mapping is performed here. it just shows you the receipts, it doesn't fix them ✨

⭐ format_tokens

reverse operation of tokenize(). that's it, that's the whole vibe. un-tokenize, slay πŸ”₯

πŸŽ€ loadmap_csv

$obj->loadmap_csv('license_map.csv', 'as');
$obj->loadmap_csv('synopsis.csv', 'lauaas#c');

Object method to load (or merge) contents of a CSV table into the object. This uses a trivial csv parser. Field separator must be ; β€” linebreaks are record separators, and the first line is ignored, if it starts with #. Fields can be surrounded by doublequotes, if a comma may be embedded. (yes bestie, you can quote your way out of comma chaos πŸ™ˆ)

The second parameter is a field template, defining what the meaning of the fields is.

  • l β€” Long name (none or once). This is a speaking name of the License: Example "Creative Commons Attribution 1.0"
  • a β€” Alias name (any number). Any other name by which the license is known: Example: "CC-BY 1.0"
  • s β€” Short name (once). The canonical (unique) short license identifier: Example: "CC-BY-1"
  • u β€” URL (any). Multiple URLs can also be written in one field, separated by whitespace.
  • # β€” License classification number (none or once). (1..5)
  • c β€” Comment (none or once)

The default template is "as", an alias, followed by the canonical short name. Empty fields are ignored, as well as fields that contain only one '?'. Thus you can use records like "","Name" to pass in a valid name without an alias. ✨

See also new() for more details about mappings.


🌈 AUTHOR 🌈

Juergen Weigert, "<jw at suse.de>" β€” thank you for your service, king πŸ‘‘


πŸ’€ BUGS πŸ’€

This module defines a different syntax than http://rpmlint.zarb.org/cgi-bin/trac.cgi/browser/trunk/TagsCheck.py β€” so like, don't @ this module about that one, it knows, it's a whole thing 😭

Please report any bugs or feature requests to "bug-rpm-license at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=License-Syntax>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. so you'll be in the loop, bestie, we love a transparent king 🫢


🫢 SUPPORT 🫢

You can find documentation for this module with the perldoc command.

perldoc License::Syntax

You can also look for information at:

  • RT: CPAN's request tracker

<http://rt.cpan.org/NoAuth/Bugs.html?Dist=License-Syntax>

  • AnnoCPAN: Annotated CPAN documentation

<http://annocpan.org/dist/License-Syntax>

  • CPAN Ratings

<http://cpanratings.perl.org/d/License-Syntax>

  • Search CPAN

<http://search.cpan.org/dist/License-Syntax/>

go lurk, go read, go thrive πŸ“šβœ¨


πŸ¦‹ ACKNOWLEDGEMENTS πŸ¦‹

(this section is literally empty in the original β€” respectfully, it said nothing, and it ate πŸ’…)


Copyright 2009 Juergen Weigert.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.


and that's a wrap, bestie πŸŽ€ this page came from perl v5.42.0, dated 2025-07-25, and you can find it filed under Syntax(3) in the User Contributed Perl Documentation. mwah, go decode some licenses πŸ’–βœ¨

πŸ“¦ where this page comes from