NAME

Test::CPAN::Health::Check::License - Check that a valid licence is declared and a licence file is present

SYNOPSIS

use Test::CPAN::Health::Check::License;

my $check  = Test::CPAN::Health::Check::License->new;
my $result = $check->run($dist);

printf "%s: %s\n", $result->status, $result->summary;

DESCRIPTION

Verifies two things:

  1. The distribution declares a specific, non-vague licence in META (i.e. not unknown, open_source, restricted, or unrestricted).

  2. A corresponding licence text file exists in the distribution root (LICENSE, LICENCE, LICENSE.txt, LICENCE.txt, LICENSE.md, LICENCE.md, or COPYING).

Score matrix:

  • 100 -- Specific licence declared and licence file present.

  • 50 -- Specific licence declared but no licence file found.

  • 0 -- No licence declared, or licence is vague/unknown.

  • skip -- No META file found.

LIMITATIONS

  • This check does not verify that the licence text in the file matches the identifier in META.

  • Licence identifiers are compared case-sensitively against the CPAN::Meta spec identifiers (lowercase, underscore-separated).

run

PURPOSE

Inspect the distribution's META licence declaration and confirm a licence text file is present in the distribution root.

API SPECIFICATION

INPUT

dist     Test::CPAN::Health::Distribution  required
context  Hashref                           optional  prior check results

OUTPUT

Test::CPAN::Health::Result with check_id 'license'.

MESSAGES

Code  | Severity | Message                                     | Resolution
------+----------+---------------------------------------------+-----------
LI001 | SKIP     | No META file -- cannot determine licence    | Add META file
LI002 | FAIL     | No licence declared in META                 | Add license field
LI003 | FAIL     | Licence declared as "{id}" -- too vague     | Use specific identifier
LI004 | WARN     | Licence declared but no licence file found  | Add LICENSE file
LI005 | PASS     | Licence declared and licence file present   |

FORMAL SPECIFICATION

-- Z schema (placeholder) --
LicenseOp
dist         : Distribution
licenses     : seq String
license_file : String | undefined
-------------------------------------------------------
meta = undefined       => status = skip
#licenses = 0          => status = fail /\ score = 0
exists vague(licenses) => status = fail /\ score = 0
license_file = undef   => status = warn /\ score = 50
license_file /= undef  => status = pass /\ score = 100

SIDE EFFECTS

None. Uses the already-parsed META object and filesystem stat calls only.

USAGE EXAMPLE

my $result = Test::CPAN::Health::Check::License->new->run($dist);
print $result->summary;

AUTHOR

Nigel Horne, <njh at nigelhorne.com>

LICENSE AND COPYRIGHT

Copyright (C) 2025-2026 Nigel Horne.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.