| 1 | 8 | ▶ | use v5.40; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use re (qw/eval/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use builtin qw(load_module); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | no warnings 'experimental::builtin'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | my $CAN_RE2 = false; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | load_module('re::engine::RE2'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | $CAN_RE2 = true; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | catch ($e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # module not compiled in / not installed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | package String::Copyright; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | String::Copyright - Representation of text-based copyright statements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | Version v0.4.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | our $VERSION = "v0.4.1"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | ▶ | use parent 'Exporter::Tiny'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | ▶ | use Log::Any qw($log); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | our @EXPORT = qw/copyright/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | PLAINTEXT => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | BLOCKS => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | FORMAT => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 8 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 8 | q{""} => '_compose', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | fallback => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | use String::Copyright; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | my $copyright = copyright(<<'END'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | copr. © 1999,2000 Foo Barbaz <fb@acme.corp> and Acme Corp. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | Copyright (c) 2001,2004 Foo (work address) <foo@zorg.corp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | Copyright 2003, Foo B. and friends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | © 2000, 2002 Foo Barbaz <foo@bar.baz> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | END | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | print $copyright; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Copyright 1999-2000 Foo Barbaz <fb@acme.com> and Acme Corp. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Copyright 2000, 2002 Foo Barbaz and Acme Corp. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # Copyright 2001, 2004 Foo (work address) <foo@zorg.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Copyright 2003 Foo B. and friends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | L<String::Copyright> identifies copyright statements in a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | and serializes them in a normalized format. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Options can be set as an argument to the 'use' statement. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | =head2 threshold, threshold_before, threshold_after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | use String::Copyright { threshold_after => 5 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | Stop parsing after this many lines without copyright information, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | before or after having found any copyright information at all. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | C<threshold> sets both C<threshold_before> and C<threshold_after>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | By default unset: All lines are parsed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | =head2 format( \&sub ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | use String::Copyright { format => \&GNU_style } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | sub GNU_style { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | my ( $years, $owners ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | return 'Copyright (C) ' . join ' ', $years || '', $owners || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | Exports one function: C<copyright>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | This module uses L<Exporter::Tiny> to export functions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | which allows for flexible import options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | see the L<Exporter::Tiny> documentation for details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 8 | my $html_xml_tags_re = qr/<\/?(?:p|br|ref)(?:\s[^>]*)?>/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # OR'ed strings have regular variable name and are already grouped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # AND'ed strings have name ending in underscore: must be grouped if repeated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 8 | my $blank = '[ \t]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | my $blank_or_break_ = "$blank*\\n?$blank*"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | my $colons_ = "$blank?:{1,2}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 8 | my $strictlabel = 'SPDX-FileCopyrightText:'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 8 | my $label = '(?i:copyright(?:-holders?)?\b|copr\.)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 | my $sign = '[©⒞Ⓒⓒ🄒🄫🅒]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 8 | my $nroff_sign_ = '\\\\[(]co'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 8 | my $pseudo_sign_ = '[({][Cc][})]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 8 | my $vague_sign_ = '-[Cc]-'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 8 | my $broken_sign_ = "\\?$blank*"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 8 | my @dash_codepoints = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | '002D', # U+002D HYPHEN-MINUS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | '02D7', # U+02D7 MODIFIER LETTER MINUS SIGN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | '2010', # U+2010 HYPHEN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | '2011', # U+2011 NON-BREAKING HYPHEN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | '2012', # U+2012 FIGURE DASH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | '2013', # U+2013 EN DASH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | '2014', # U+2014 EM DASH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | '2015', # U+2015 HORIZONTAL BAR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | '2043', # U+2043 HYPHEN BULLET | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | '2212', # U+2212 MINUS SIGN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 'FE63', # U+FE63 SMALL HYPHEN-MINUS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 'FF0D', # U+FF0D FULLWIDTH HYPHEN-MINUS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | my $dash = '[' . join( '', map { chr( hex($_) ) } @dash_codepoints ) . '-]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | my %soup_patterns = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | "\xC2\xA9" => 'UTF-8 © (C2 A9) mis-read as two latin1 chars "©"', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | "\xA1\xA4" => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 'EUC-JP © (JIS X 0208 row 01 col 01), read as latin1 as "¡¤"', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | "\x81\x98" => 'Shift-JIS / CP932 ©, read as latin1 as two C1 controls', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | "\xA2\xA9" => 'GBK © (Chinese, code page 936), read as latin1 as "¢©"', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 8 | my %dash_soup = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | "\x{E2}\x{80}\x{93}" => 'EN-DASH (UTF-8 as Latin-1)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | "\x{E2}\x{80}\x{94}" => 'EM-DASH (UTF-8 as Latin-1)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | "\x{E2}\x{20AC}\x{201C}" => 'EN-DASH (UTF-8 as CP1252)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | "\x{E2}\x{20AC}\x{201D}" => 'EM-DASH (UTF-8 as CP1252)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | "\x{0432}\x{0402}\x{2019}" => 'EN-DASH (UTF-8 as CP1251)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | "\x{0432}\x{0402}\x{201D}" => 'EM-DASH (UTF-8 as CP1251)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 16 | ▶ | my $_build_alt = sub ($table) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 16 | my @alt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 16 | for my $pat ( sort { length $b <=> length $a } keys %$table ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | my $esc = join '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 80 | map { '\x{' . sprintf( '%X', ord ) . '}' } split //, $pat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 80 | push @alt, $esc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 16 | return join '|', @alt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 8 | my $sign_soup_ = $_build_alt->( \%soup_patterns ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 8 | my $dash_soup_ = $_build_alt->( \%dash_soup ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # high-bit © noise, caused by misparsing UTF-8 as latin1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # except \xA2 (GBK © lead byte ¢©), \xAE (latin1 ©), \xAE (MacRoman ©) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # and \xE2 (latin1 © lowercased after misparse) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 8 | my $nonsign_ = '[\x80-\xA1\xA3-\xAB\xAD-\xC1\xC3-\xE1\xE3-\xFF]\xA9'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 8 | my $nonidentifier_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | = "(?:no |_|$dash)copyright|copyright-[^h]|(?:Digital Millennium|U.S.|US|United States) Copyright Act|\\b(?:for|we) copyright\\b"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # this should cause *no* false positives, and stop-chars therefore | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # exclude e.g. email address building blocks; tested against the code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # corpus at https://codesearch.debian.net/ (tricky: its RE2 engine lacks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # support for negative groups) using searches like these: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # (?i)copyright (?:(?:claim|holder|info|information|notice|owner|ownership|statement|string)s?|in|is|to)@\w | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # (?i)copyright (?:(?:claim|holder|info|information|notice|owner|ownership|statement|string)s?|in|is|to)@\b[-_@] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # (?im)copyright (?:(?:claim|holder|info|information|notice|owner|ownership|statement|string)s?|in|is|to)[^ $] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 8 | my $identifier_action | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | = '(?i:apply|applied|applies|assigned|generated|transfer|transferred)'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 8 | my $identifier_thing_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | = '(?i:block|claim|date|disclaimer|holder|info|information|interest|law|license|notice|owner|ownership|permission|sign|statement|string|symbol|tag|text)s?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | my $identifier_misc | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | = "(?i:and|are|at|eq|for|if|in|is|of|on|or|,${blank}patent|this|to|the (?:library|software),|treaty)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 8 | my $identifier_chatter | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | = "(?:$identifier_action|$identifier_thing_|$identifier_misc)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 8 | my $the_notname | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | = '(?i:concrete|fault|first|immediately|least|min\/max|one|outer|previous|ratio|sum|user)'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 8 | my $the_sentence_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | = "(?:\\w+$blank+){1,10}(?i:are|can(?:not)?|in|is|must|was)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | my $pseudosign_chatter_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | = "(?:(?:the$blank+(?:$the_notname|$the_sentence_)|all begin|there|you must)\\b|,? \\(?\\w\\))"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 8 | my $chatter | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | = "(?im:$nonsign_|$nonidentifier_|copyright$blank_or_break_$identifier_chatter(?:\\z|@\\W|[^a-zA-Z0-9@_-])|$blank*$pseudo_sign_(?:$blank_or_break_)+$pseudosign_chatter_)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 8 | my $nonyears_ = '\W?(?i:year|19[xy]{2}|[xy]{4})\W?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 8 | my $year_ = '\b[0-9]{4}\b'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 8 | my $comma_spacy = "(?:$blank*,$blank_or_break_|$blank_or_break_,?$blank*)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 8 | my $dash_spacy_ = "$blank*$dash(?:$blank_or_break_)*"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 8 | my $colon_or_dash = "(?:$colons_$blank_or_break_|$blank?$dash\{1,2}$blank)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 8 | my $delimiter = "(?:$colon_or_dash|$comma_spacy)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 8 | my $vague_year_ = "(?:$dash$blank?)?[0-9]{1,5}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | my $owner_intro_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | = "(?:$colon_or_dash|$pseudo_sign_$blank?|\\bby$blank_or_break_)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | my $owner_prefix = '[(*<@\[{]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 8 | my $owner_initial = '[^\s!"#$%&\'()*+,./:;<=>?@[\\\\\]^_`{|}~-]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 8 | my $signs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | = "(?m:$strictlabel$blank*|(?:$label|$sign|$nroff_sign_|(?:^|$blank)$pseudo_sign_)(?:$colon_or_dash?$blank*(?:$label|$sign|$pseudo_sign_))*)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 8 | my $yearspan_ = "$year_(?:$dash_spacy_$year_)?"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | my $years_ = "$yearspan_(?:$comma_spacy$yearspan_)*"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | my $owners_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | = "(?:$vague_year_|$owner_prefix*$owner_initial\\S*)(?:$blank*\\S+)*"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # compile regexps in isolation to limit use of RE2 engine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 8 | my ($dash_spacy_re, $owner_intro_A_re, $boilerplate_X_re, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | $signs_and_more_re | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 8 | ▶ | BEGIN { re::engine::RE2->import( -strict => 1 ) if ($CAN_RE2) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | $dash_spacy_re = qr/$dash_spacy_/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | $owner_intro_A_re = qr/^$owner_intro_/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 8 | $boilerplate_X_re | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | = qr/(?i)${comma_spacy}All$blank+Rights$blank+Reserved[.!]?.*/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | $signs_and_more_re | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | = qr/$chatter|$signs(?:$blank$vague_sign_)?$delimiter(?:$broken_sign_)?(?:$nonyears_|((?:$years_$delimiter)?(?:(?:$owner_intro_)?$owners_)?))|\n/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | sub _merge_ranges | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 70 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_ranges: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 70 | ▶ | my @ranges = map { ref $_ ? [@$_] : [ $_, $_ ] } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 70 | ▶ | @ranges = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @ranges; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$String::Copyright::a->[0] <=> $String::Copyright::b->[0] || $String::Copyright::a->[1] <=> $String::Copyright::b->[1]
MC/DC50%1/2
$String::Copyright::a->[0] <=> $String::Copyright::b->[0] || $String::Copyright::a->[1] <=> $String::Copyright::b->[1]
$String::Copyright::a->[0] <=> $String::Copyright::b->[0]
$String::Copyright::a->[1] <=> $String::Copyright::b->[1]
Truth table66%2/3
A || B
A= $String::Copyright::a->[0] <=> $String::Copyright::b->[0]B= $String::Copyright::a->[1] <=> $String::Copyright::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 70 | my @merged; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 70 | for my $r (@ranges) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 97 | ▶ | if ( @merged && $r->[0] <= $merged[-1][1] + 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@merged and $r->[0] <= $merged[-1][1] + 1
MC/DC100%2/2
@merged and $r->[0] <= $merged[-1][1] + 1
@merged
$r->[0] <= $merged[-1][1] + 1
Truth table100%3/3
A and B
A= @mergedB= $r->[0] <= $merged[-1][1] + 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 23 | ▶ | $merged[-1][1] = $r->[1] if $r->[1] > $merged[-1][1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 74 | push @merged, [@$r]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 70 | return @merged; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | sub _generate_copyright | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_copyright: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 14 | my ( $class, $name, $args, $globals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 211 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=39 SCAR=38.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 211 | my $copyright = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | Carp::croak("String::Copyright strings require defined parts") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 211 | ▶ | unless 1 + @_ == grep {defined} $copyright, @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # String::Copyright objects are effectively immutable and can be reused | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 211 | ▶ | if ( !@_ && blessed($copyright) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @_ and builtin::blessed($copyright)
MC/DC0%0/2
not @_ and builtin::blessed($copyright)
not @_
builtin::blessed($copyright)
Truth table33%1/3
not(A) and B
A= not @_B= builtin::blessed($copyright)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | return $copyright; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # stringify objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 211 | $copyright = "$copyright"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 211 | my %changed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 211 | my $pre = $copyright; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 211 | ▶ | if ( my $c = $copyright =~ s{$html_xml_tags_re}{}g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $changed{html} = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 211 | ▶ | if ( my $c = $copyright =~ s/$dash_soup_/-/g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 9 | $changed{dash_soup} = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 211 | ▶ | if ( $copyright =~ /(?:$sign)|(?i:copyright\b)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 185 | ▶ | if ( my $c = $copyright =~ s/$sign_soup_/©/g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 7 | $changed{sign_soup} = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 211 | ▶ | if ( ( my $c = $copyright =~ s/$dash/-/g ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 42 | $changed{dash} = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 42 | ▶ | if ( $log->is_trace ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 9 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | my @notes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 9 | ▶ | while ( $pre =~ /[$dash]/g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my $cp = ord $&; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | next if $cp == 0x2D; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | next if $seen{$cp}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | push @notes, sprintf( 'U+%04X', $cp ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 9 | ▶ | $changed{dash} = \@notes if @notes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 211 | ▶ | if (%changed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 49 | ▶ | if ( $log->is_trace ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 15 | $log->trace( 'normalized copyright string', \%changed ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 34 | $log->debugf( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 'normalized copyright string: %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | join( ', ', sort keys %changed ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # TODO: also parse @_ - but each separately! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 211 | my @block; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 211 | my $skipped = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 211 | ▶ | while ( $copyright =~ /$signs_and_more_re/g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 292 | my $owners = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 292 | ▶ | if ( $globals->{threshold_before} || $globals->{threshold} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$globals->{"threshold_before"} or $globals->{"threshold"}
MC/DC50%1/2
$globals->{"threshold_before"} or $globals->{"threshold"}
$globals->{"threshold_before"}
$globals->{"threshold"}
Truth table66%2/3
A or B
A= $globals->{"threshold_before"}B= $globals->{"threshold"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | !@block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | and !length $owners | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | and ++$skipped >= ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | $globals->{threshold_before} || $globals->{threshold} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 24 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not @block || length $owners and ++$skipped >= ($globals->{"threshold_before"} || $globals->{"threshold"})
@block || length $owners
$globals->{'threshold_before'} || $globals->{'threshold'}
MC/DC100%3/3
not @block || length $owners and ++$skipped >= ($globals->{"threshold_before"} || $globals->{"threshold"})
@block
length $owners
++$skipped >= ($globals->{"threshold_before"} || $globals->{"threshold"})
MC/DC0%0/2
$globals->{'threshold_before'} || $globals->{'threshold'}
$globals->{'threshold_before'}
$globals->{'threshold'}
Truth table100%4/4
not(A || B) and C
A= @blockB= length $ownersC= ++$skipped >= ($globals->{"threshold_before"} || $globals->{"threshold"})
Truth table33%1/3
A || B
A= $globals->{'threshold_before'}B= $globals->{'threshold'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 290 | ▶ | if ( $globals->{threshold_after} || $globals->{threshold} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$globals->{"threshold_after"} or $globals->{"threshold"}
MC/DC50%1/2
$globals->{"threshold_after"} or $globals->{"threshold"}
$globals->{"threshold_after"}
$globals->{"threshold"}
Truth table66%2/3
A or B
A= $globals->{"threshold_after"}B= $globals->{"threshold"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # "after" detects end of _current_ line so is skewed by one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | @block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | and !length $owners | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | and ++$skipped >= 1 + ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | $globals->{threshold_after} || $globals->{threshold} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 14 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
@block and not length $owners and ++$skipped >= 1 + ($globals->{"threshold_after"} || $globals->{"threshold"})
@block and not length $owners
$globals->{'threshold_after'} || $globals->{'threshold'}
MC/DC100%3/3
@block and not length $owners and ++$skipped >= 1 + ($globals->{"threshold_after"} || $globals->{"threshold"})
@block
not length $owners
++$skipped >= 1 + ($globals->{"threshold_after"} || $globals->{"threshold"})
MC/DC0%0/2
$globals->{'threshold_after'} || $globals->{'threshold'}
$globals->{'threshold_after'}
$globals->{'threshold'}
Truth table100%4/4
A and not(B) and C
A= @blockB= not length $ownersC= ++$skipped >= 1 + ($globals->{"threshold_after"} || $globals->{"threshold"})
Truth table33%1/3
A || B
A= $globals->{'threshold_after'}B= $globals->{'threshold'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 288 | ▶ | next if ( !length $owners ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 144 | $skipped = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 144 | my $years; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 144 | my @span = $owners =~ /\G($yearspan_)(?:$comma_spacy|\Z)/gm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 144 | ▶ | if (@span) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 70 | $owners = $'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # deduplicate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 70 | my @ranges; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 70 | for (@span) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 97 | my ( $y1, $y2 ) = split /$dash_spacy_re/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 97 | ▶ | if ( !$y2 ) { push @ranges, $y1; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | elsif ( $y1 > $y2 ) { push @ranges, [ $y2, $y1 ]; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 21 | else { push @ranges, [ $y1, $y2 ]; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # normalize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | $years = join ', ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 70 | ▶ | map { $_->[0] == $_->[1] ? $_->[0] : "$_->[0]-$_->[1]" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | _merge_ranges(@ranges); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 144 | ▶ | if ($owners) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 138 | $owners =~ s/$owner_intro_A_re//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 138 | $owners =~ s/\s{2,}/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 138 | $owners =~ s/$owner_intro_A_re//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 138 | $owners =~ s/$boilerplate_X_re//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # split owner into owner_id and owner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 144 | ▶ | push @block, [ $years || undef, $owners || undef ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$years || undef
$owners || undef
MC/DC100%1/1
$years || undef
$years
MC/DC100%1/1
$owners || undef
$owners
Truth table100%2/2
A
A= $years
Truth table100%2/2
A
A= $owners
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # TODO: save $skipped to indicate how dirty parsing was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 211 | my $ext_format = $globals->{format}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | my $format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | = $globals->{format} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 110 | ▶ | ? sub { $ext_format->( $_->[0], $_->[1] ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 211 | ▶ | : sub { join ' ', '©', $_->[0] || (), $_->[1] || () }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.8
Branch: 1 branch
Condition50%3/6
$_->[0] || ()
$_->[1] || ()
MC/DC0%0/2
$_->[0] || ()
$_->[0]
()
MC/DC0%0/2
$_->[1] || ()
$_->[1]
()
Truth table66%2/3
A || B
A= $_->[0]B= ()
Truth table33%1/3
A || B
A= $_->[1]B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 211 | bless [ $copyright, \@block, $format ], __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 14 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my ( $self, @data ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | Carp::croak("String::Copyright require defined, positive-length parts") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | unless 1 + @_ == grep { defined && length } @data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # String::Copyright objects are simply stripped of their string part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if ( !@_ && blessed($self) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @_ and builtin::blessed($self)
MC/DC0%0/2
not @_ and builtin::blessed($self)
not @_
builtin::blessed($self)
Truth table0%0/3
not(A) and B
A= not @_B= builtin::blessed($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | return bless [ undef, $data[1] ], __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # FIXME: properly validate data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | Carp::croak("String::Copyright blocks must be an array of strings") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | unless @_ == grep { reftype($_) eq 'ARRAY' } @data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | bless [ undef, \@data ], __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | sub _compose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 248 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compose: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 248 | my $format = $_[0]->[FORMAT]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 248 | join "\n", map {&$format} @{ $_[0]->[BLOCKS] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | sub is_normalized { !defined $_[0]->[PLAINTEXT] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_normalized: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | L<Encode> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | L<Exporter::Tiny> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | =head1 BUGS/CAVEATS/etc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | L<String::Copyright> operates on strings, not bytes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | Data encoded as UTF-8, Latin1 or other formats | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | need to be decoded to strings before use. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | Only ASCII characters and B<©> (copyright sign) are directly processed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | If copyright sign is not detected | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | or accents or multi-byte characters display wrong, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | then most likely the data was not decoded into a string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | Some common mis-decoded forms of the copyright sign are recognized and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | normalized to B<©> (e.g. UTF-8 read as Latin1, EUC-JP, Shift-JIS/CP932, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | and GBK). When this happens a warning is emitted via L<Log::Any>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | If ranges or lists of years are not tidied, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | then maybe it contained non-ASCII whitespace or digits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | Jonas Smedegaard C<< <dr@jones.dk> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | This program is based on the script "licensecheck" from the KDE SDK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | originally introduced by Stefan Westerfeld C<< <stefan@space.twc.de> >>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | Copyright © 2007, 2008 Adam D. Barratt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | Copyright © 2005-2012, 2016, 2018, 2020-2021 Jonas Smedegaard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | Copyright © 2018, 2020-2021 Purism SPC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | This program is free software: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | under the terms of the GNU Affero General Public License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | as published by the Free Software Foundation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | either version 3, or (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | but WITHOUT ANY WARRANTY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | without even the implied warranty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | See the GNU Affero General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | You should have received a copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | of the GNU Affero General Public License along with this program. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | If not, see <https://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||