| 1 | ## -*- Mode: CPerl -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # File: Getopt::Gen.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Author: Bryan Jurish <moocow@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Description: Parser for extended '.ggo' (gengetopt) files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | package Getopt::Gen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Carp qw(carp confess); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Text::Template; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Parse::Lex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Parse::Token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Getopt::Gen::Parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | %EXPORT_TAGS = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | utils=>[qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | long2cname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | podify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | string_value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | dequote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | @EXPORT_OK = (map { @$_ } values(%EXPORT_TAGS)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # GLOBALS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | our $VERSION = "0.14"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | our %DEFAULT_TEMPLATE_NEWARGS = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | our %DEFAULT_TEMPLATE_HASHARGS = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | Getopt::GenVersion=>$VERSION, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | og=>undef, # this will be the Getopt::Gen object itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | our %DEFAULT_TEMPLATE_FILLARGS = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | DELIMITERS=>['[@','@]'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | BROKEN=>\&template_broken, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | BROKEN_ARG=>undef, # gets { NAME=>$og->{name},SOURCE=>$user_source,%user_broken_arg } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # whether to carp()/croak() on complain()/wigout() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | our $VERBOSE = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # Natural language names for parser & lexer internals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | our %NL_XLATE = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ## error message literals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | SYNTAX_ERROR => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | "__NAME__: Syntax error in __FILE__ at line __LINE__ column __COL__, near `__CURTEXT__'\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ." > Expected one of: __EXPECTED__\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ." > Got: __CURTOK__\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | SEMANTIC_ERROR => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | "__NAME__: Semantic error in __FILE__ at line __LINE__ column __COL__, near `__CURTEXT__'\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ." > Hint: __HINT__\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ." > Got: `__CURTEXT__'\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | LEXER_ERROR => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | "__NAME__: Tokenization error in __FILE__ at line __LINE__ column __COL__, near `__CURTEXT__'\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ." > Hint: __HINT__\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ## lexer tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | COMMENT => '<a comment>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | #EQUALS => "=", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | #DBLQUOTE => '"', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | SYMBOL => '<a symbol>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | STRING => '<a string>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | NEWLINE => '<a newline>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | #ONOFF => '<an on/off value>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | #YESNO => '<a yes/no value>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | #OTYPE => '<a token type>' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ## parser nonterminals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | optspec => '<a specification>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ## Lexer Hints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ILLEGAL_CHAR => "Illegal character `__MATCH__'.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | UNKNOWN_LEXER_HINT => "???", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ## Parser Hints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ##-------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | NOT_SHORT_ENOUGH => "Short option names must be single-characters.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Lexical Analysis variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # + Variable-name prefix conventions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # - $OG_ : any Getopt::Gen token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # $OG_SYMINIT, $OG_SYMBODY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # + characters for symbol tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | our $OG_SYMINIT = '\w\d'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | our $OG_SYMBODY = '\w\d\.\_\-'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | our $OG_SYMBOL = '(?:['.$OG_SYMINIT.']['.$OG_SYMBODY.']*)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # $OG_TOK_(BEG|EWND) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # + separator regexes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | our $OG_TOK_BEG = '(?<!['.$OG_SYMBODY.'])'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | our $OG_TOK_END = '(?!['.$OG_SYMBODY.'])'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # $OG_NEWLINE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # + newline characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | our $OG_NEWLINE = '\n\r'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # $OG_ANY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # + any known character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | our $OG_ANY = '.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # Special keywords added to lexer tokens (TOK_* constants) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | our @OG_KEYWORDS = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | rcfile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | podpreamble | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | purpose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | on_reparse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | unnamed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | argument | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | option | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | on off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | yes no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | funct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | toggle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | int short long | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | float double longdouble | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # @LEXER_TOKENS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # + Tokenization specification for Parse::Lex lexer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # + the 'SEARCH_TOKEN' type is further checked by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # the yylex() sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | our @LEXER_TOKENS = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ## -- curly-braces (special handling by _yylex_sub()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 'ALL:LBRACE', '{', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 'ALL:RBRACE', '}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 'BRACED:STRING', '[^\{\}]*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ## Comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 'COMMENT', '(?:\#[^'.$OG_NEWLINE.']*)', \&yyignore, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | Parse::Token::Delimited->new(Name=>'MULTILINE_COMMENT', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | Start => '/[*]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | End => '[*]/', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | Sub=>\&yyignore), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | ## Keyword symbols | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | (map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 25 | my $kwname = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 25 | my $kwregex = $OG_TOK_BEG.$kwname.$OG_TOK_END; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 25 | $kwname =~ tr/a-z/A-Z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 25 | ('TOK_'.$kwname,$kwregex) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } @OG_KEYWORDS), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ## Newlines are lexical elements (ick) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 'NEWLINE', '['.$OG_NEWLINE.']+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ## Special symbols | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 'MINUS', '\-', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 'EQUALS', '\=', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 'ESCAPED_NEWLINE', '\\\\['.$OG_NEWLINE.']', \&yyignore, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | ## Literal symbols | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 'SYMBOL', $OG_SYMBOL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | ## Strings (double-quoted) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | Parse::Token::Quoted->new(Name=>'DQ_STRING', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | Handler=>'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | Escape=>'\\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | Quote=>'"', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | Sub=>sub { dequote($_[1],'"'); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | ## Strings (single-quoted) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | Parse::Token::Quoted->new(Name=>'SQ_STRING', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | Handler=>'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | Escape=>'\\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | Quote=>'\'', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | Sub=>sub { dequote($_[1],"'"); }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | ## Strings (back-quoted) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | Parse::Token::Quoted->new(Name=>'BQ_STRING', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | Handler=>'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | Escape=>'\\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | Quote=>'`', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | Sub=>sub { bq_dequote($_[1],"`"); }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=16 SCAR=56.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my ($that,%args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | my $class = ref($that)||$that; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $og = bless | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ## -- user data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | USER => {}, # hashref to user-strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ## -- new parsing data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | parser => undef, # Getopt::Gen::Parser object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | lexer => undef, # Parse::Lex lexer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | yylex => undef, # lexer sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | yyerr => undef, # error sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | errstr => undef, # last error message (undef on success) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | ## -- i/o data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | name=> __PACKAGE__ , # name to use for error-reporting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | infile=>undef, # input filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | infh=>undef, # input filehandle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | outfile=>undef, # output filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | outfh=>undef, # output filehandle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | #TEMPLATE_ARGS=>{}, # args for template | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | ## -- generation-flags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | filename=>'cmdline', # basename of output file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | funcname=>'cmdline_parser', # name of parsing-function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | structname=>'gengetopt_args_info', # name of parser-structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | longhelp=>0, # long usage line in help ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | unnamed=>0, # allow non-option arguments ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | reparse_action=>'error', # what to do when an option is re-given: error|warn|clobber | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | handle_help=>1, # whether to handle '-h' and '--help' options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | handle_version=>1, # whether to handle '-V' and '--version' options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | handle_rcfile=>1, # whether to handle '-c' and '--rcfile' options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | handle_error=>1, # whether to exit on errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | want_timestamp=>0, # whether to add timestamp to pod files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | ## -- parsed data from input file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | package => undef, # program package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | #program => undef, # program name (in USER) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | version => undef, # program version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | purpose => undef, # brief description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | podpreamble => undef, # pod preamble | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | rcfiles => [], # default config files (literals!) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | args => [], # [ {name=>$arg1name,descr=>$arg1descr},... ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | user_code => undef, # literal user code for .c file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | group => 'Options', # name of current group (used during parsing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | optl => [], # list of options in order given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | opth => {}, # { $optid1=>$opt1, ..., } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | optshort => {}, # { $short1=>$opdid1, ...} : for conflict-resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | optlong => {}, # { $long1=>$opdid1, ...} : for conflict-resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | #%{$og->{TEMPLATE_ARGS}} = %DEFAULT_TEMPLATE_ARGS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my ($arg,$aval); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | while (($arg,$aval) = each(%args)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if (exists($og->{$arg})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (ref($og->{$arg}) && ref($og->{$arg}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $og->{$arg} and ref $og->{$arg} eq "HASH"
MC/DC0%0/2
ref $og->{$arg} and ref $og->{$arg} eq "HASH"
ref $og->{$arg}
ref $og->{$arg} eq "HASH"
Truth table0%0/3
A and B
A= ref $og->{$arg}B= ref $og->{$arg} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | %{$og->{$arg}} = (%{$og->{$arg}}, %$aval); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | ▶ | elsif (ref($og->{$arg}) && ref($og->{$arg}) eq 'ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $og->{$arg} and ref $og->{$arg} eq "ARRAY"
MC/DC0%0/2
ref $og->{$arg} and ref $og->{$arg} eq "ARRAY"
ref $og->{$arg}
ref $og->{$arg} eq "ARRAY"
Truth table0%0/3
A and B
A= ref $og->{$arg}B= ref $og->{$arg} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | @{$og->{$arg}} = @$aval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $og->{$arg} = $aval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | carp(__PACKAGE__ , "::new(): ignoring unknown keyword '$arg'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | ## -- sanity check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my @reparse_actions = qw(error warn clobber); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | if (!grep { $_ eq $og->{reparse_action} } @reparse_actions) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | carp(__PACKAGE__ , "::new(): unknown reparse_action keyword '$_' -- using 'error'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $og->{reparse_action} = 'error'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ## -- setup new lexer/parser pair | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if (!defined($og->{lexer})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | Parse::Lex->exclusive('BRACED'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $og->{lexer} = Parse::Lex->new | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | @LEXER_TOKENS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | qw(ERROR .*), $og->lexer_error() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $og->{lexer}->skip('[ \t]*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # $og->{lexer}->skip('\[ \t]*(?:#(?:[^'.$OG_NEWLINE.']*)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # .'|[ \t]+' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # .'|(?:\\\\['.$OG_NEWLINE.'])' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # .')[ \t]*'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # $og->{lexer}->skip('\s*(?:#(?s:.*)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # .'|\s+' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # .'|\\\\['.$OG_NEWLINE.']' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # .')\s*'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | $og->{parser} = Getopt::Gen::Parser->new() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if (!defined($og->{parser})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | $og->{yylex} = $og->_yylex_sub() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | if (!defined($og->{yylex})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | $og->{yyerror} = $og->_yyerror_sub() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if (!defined($og->{yyerror})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | ## -- add auto-handlers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | if ($og->{handle_help}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | #$oid = $og->parse_option(q("help" h "Print help and exit" no)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | $og->add_option({short=>'h', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | long=>'help', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | descr=>'Print help and exit.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | is_help=>1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | },$og->{parser}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ($og->{handle_version}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | $og->add_option({short=>'V', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | long=>'version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | descr=>'Print version and exit.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | is_version=>1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | },$og->{parser}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ($og->{handle_rcfile}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | $og->add_option({short=>'c', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | long=>'rcfile', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | descr=>'Read an alternate configuration file.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | type=>'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | arg=>'FILE', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | is_rcfile=>1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | },$og->{parser}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | return $og; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # Destructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # + close files and break all references | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if (defined($_[0]->{infh}) && $_[0]->{infh}->opened()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_[0]{"infh"} and $_[0]{"infh"}->opened
MC/DC0%0/2
defined $_[0]{"infh"} and $_[0]{"infh"}->opened
defined $_[0]{"infh"}
$_[0]{"infh"}->opened
Truth table0%0/3
A and B
A= defined $_[0]{"infh"}B= $_[0]{"infh"}->opened
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $_[0]->{infh}->close(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | %{$_[0]} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # Accessors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | sub lexer { return $_[0]->{lexer}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lexer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | sub parser { return $_[0]->{parser}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parser: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | sub errstr { return $_[0]->{errstr}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errstr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # Parsing: high-level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # $parse_status = $og->parse($file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # + on failure, returns undef $og->errstr() holds an error message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my ($og,$file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $og->reset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $og->{infile} = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | my $fh = ref($file) ? $file : IO::File->new("<$file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if (!$fh) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $og->complain("open failed for file '$file': $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $og->{infh} = $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | $og->{lexer}->from($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $og->{parser}{USER}{og} = $og; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $result = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | $og->{parser}->YYParse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | yylex => $og->{yylex}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | yyerror => $og->{yyerror}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | #yydebug => 0x01, # lexer debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | #yydebug => 0x02, # state info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | #yydebug => 0x04, # driver actions (shift/reduce/etc.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | #yydebug => 0x08, # stack dump | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | #yydebug => 0x10, # Error recovery trace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | #yydebug => 0x01 | 0x02 | 0x04 | 0x08, # almost everything | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # -- cleanup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | delete $og->{parser}{USER}{og}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $fh->close(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | @$og{qw(infile infh)} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # everything was kosher... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | return $result unless ($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # ... or it wasn't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $og->{errstr} = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # ---- DEBUG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # $result = $og->dummylex(@strings_or_filehandles); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | sub dummylex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dummylex: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my $og = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $og->{lexer}->reset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my ($name,$text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | foreach (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $og->{infile} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $og->{lexer}->from($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | TOKEN:while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ($name,$text) = &{$og->{yylex}}(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | if ($name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | print("-" x 64, "\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ">> Line: ", $og->{lexer}->line, ", Pos: ", $og->{lexer}->pos, "\n", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | ">> Type: ", $name, "\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | ">> Text: `", $text, "'\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | last TOKEN if ($name eq 'ERROR'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | last TOKEN; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | print("-" x 64, "\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | ">> Line: ", $og->{lexer}->line, ", Pos: ", $og->{lexer}->pos, "\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | ">> Text: `", (defined($text) ? $text : '<undef>'), "'\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | ">> EOF\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # METHODS : generation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # $template_output = fill_in(%args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | sub fill_in { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fill_in: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my ($og,%userargs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my %args = %userargs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | $og->{template} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | Text::Template->new(%DEFAULT_TEMPLATE_NEWARGS,%args) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | or $og->wigout("could not create Text::Template object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | delete(@args{qw(SOURCE TYPE)}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | my $hashargs = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | %DEFAULT_TEMPLATE_HASHARGS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | og=>$og, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | (exists($args{HASH}) ? %{$args{HASH}} : qw()), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | SOURCE=>$userargs{SOURCE}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | delete($args{HASH}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | my $brokenargs = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | NAME=>$og->{name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | SOURCE=>$userargs{SOURCE}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | (exists($args{BROKEN_ARG}) ? (%{$args{BROKEN_ARG}}) : qw()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | $og->{template}->fill_in( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | %DEFAULT_TEMPLATE_FILLARGS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | HASH=>$hashargs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | %args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | (exists($args{BROKEN}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | ? (BROKEN_ARG=>$args{BROKEN_ARG}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | : (BROKEN_ARG=>$brokenargs)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # broken(%args) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # + called when things go wrong | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # + %args keys: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # text=>$failed_perl_fragment, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # lineno=>$template_input_line_number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # error=>$@_of_failed_perl_frag, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | # arg=>$USER_REFERENCE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # + here, arg is the same as the template's HASH. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | sub template_broken { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
template_broken: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | my (%args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | print STDERR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | ("$args{arg}{NAME}: '$args{arg}{SOURCE}', line $args{lineno}: $args{error}\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | ($VERBOSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | ? ("> Code Fragment: \n> ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | (defined($args{text}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | ▶ | ? join("\n> ", split(/\n/,$args{text})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | : '(undefined, sorry)'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | "\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | : qw()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | return undef; ## -- abort | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # METHODS: MANIPULATORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # $optid = $og->add_option($opt,$parser) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # + parses a partial option-hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # + to be called by parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | sub add_option { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_option: not called CC=48 SCAR=77.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my ($og,$opt,$ogp) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | ## -- get basic data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | my ($short,$long,$descr,$type,$default,$required) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | @$opt{qw(short long descr type default required)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | $type = 'funct' if (!defined($type)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | $long = '-' if (!defined($long)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | $short = '-' if (!defined($short)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | $descr = '???' if (!defined($descr)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | #$default = 0 if (!defined($default)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | $required = 0 if (!defined($required)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | $long = string_value($long); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $short = string_value($short); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | $descr = string_value($descr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | $default = string_value($default); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my $optid = "$short|$long"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | ## -- sanity check(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | if (exists($og->{optshort}{$short}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/9
exists $og->{"optshort"}{$short} and exists $og->{"optlong"}{$long} and $og->{"optshort"}{$short} eq $optid and $og->{"optlong"}{$long} eq $optid
exists $og->{"optshort"}{$short} and exists $og->{"optlong"}{$long} and $og->{"optshort"}{$short} eq $optid
exists $og->{"optshort"}{$short} and exists $og->{"optlong"}{$long}
MC/DC0%0/4
exists $og->{"optshort"}{$short} and exists $og->{"optlong"}{$long} and $og->{"optshort"}{$short} eq $optid and $og->{"optlong"}{$long} eq $optid
exists $og->{"optshort"}{$short}
exists $og->{"optlong"}{$long}
$og->{"optshort"}{$short} eq $optid
$og->{"optlong"}{$long} eq $optid
Truth table0%0/5
A and B and C and D
A= exists $og->{"optshort"}{$short}B= exists $og->{"optlong"}{$long}C= $og->{"optshort"}{$short} eq $optidD= $og->{"optlong"}{$long} eq $optid
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | && exists($og->{optlong}{$long}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | && $og->{optshort}{$short} eq $optid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | && $og->{optlong}{$long} eq $optid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | $og->complain("option '$optid' multiply specified -- overriding."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | ▶ | elsif ($short ne '-' && exists($og->{optshort}{$short})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$short ne "-" and exists $og->{"optshort"}{$short}
MC/DC0%0/2
$short ne "-" and exists $og->{"optshort"}{$short}
$short ne "-"
exists $og->{"optshort"}{$short}
Truth table0%0/3
A and B
A= $short ne "-"B= exists $og->{"optshort"}{$short}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | return $og->wigout | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | ("conflict for short option '$short': old=($og->{optshort}{$short}), new=($optid)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | ▶ | elsif ($long ne '-' && exists($og->{optlong}{$long})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$long ne "-" and exists $og->{"optlong"}{$long}
MC/DC0%0/2
$long ne "-" and exists $og->{"optlong"}{$long}
$long ne "-"
exists $og->{"optlong"}{$long}
Truth table0%0/3
A and B
A= $long ne "-"B= exists $og->{"optlong"}{$long}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | return $og->wigout | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | ("conflict for long option $long: old=($og->{optlong}{$long}), new=($optid)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | ## -- add the option to our list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | push(@{$og->{optl}},$optid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | ## -- type-dependent initialization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | if ($type eq 'funct') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | ## -- funct ('funct-opt') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | $default = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | $opt->{cname} = long2cname($long ne '-' ? $long : $short) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | if (!defined($opt->{cname})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | $opt->{cgiven} = cname2given($opt->{cname}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | if (!defined($opt->{cgiven})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | ▶ | elsif ($type eq 'flag' || $type eq 'flag2') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type eq "flag" or $type eq "flag2"
MC/DC0%0/2
$type eq "flag" or $type eq "flag2"
$type eq "flag"
$type eq "flag2"
Truth table0%0/3
A or B
A= $type eq "flag"B= $type eq "flag2"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | ## -- flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | $opt->{cname} = long2cname($long ne '-' ? $long : $short).'_flag' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | ▶ | if (!defined($opt->{cname})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | $opt->{cgiven} = cname2given($opt->{cname}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | if (!defined($opt->{cgiven})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | $default = 0 if (!defined($default)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | elsif ($type eq 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | ## -- strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | $opt->{cname} = long2cname($long ne '-' ? $long : $short).'_arg' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | if (!defined($opt->{cname})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | $opt->{cgiven} = cname2given($opt->{cname}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | if (!defined($opt->{cgiven})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | $default = 'NULL' if (!defined($default)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # argument name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | if (!defined($opt->{arg})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $opt->{arg} = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | $opt->{arg} =~ tr/a-z/A-Z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | ▶ | elsif ($type eq 'int' || $type eq 'short' || $type eq 'long') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$type eq "int" or $type eq "short" or $type eq "long"
$type eq "int" or $type eq "short"
MC/DC0%0/3
$type eq "int" or $type eq "short" or $type eq "long"
$type eq "int"
$type eq "short"
$type eq "long"
Truth table0%0/4
A or B or C
A= $type eq "int"B= $type eq "short"C= $type eq "long"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | ## -- integer types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | $opt->{cname} = long2cname($long ne '-' ? $long : $short).'_arg' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if (!defined($opt->{cname})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | $opt->{cgiven} = cname2given($opt->{cname}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | if (!defined($opt->{cgiven})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | $default = 0 if (!defined($default)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | # argument name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | if (!defined($opt->{arg})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | $opt->{arg} = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | $opt->{arg} =~ tr/a-z/A-Z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | ▶ | elsif ($type eq 'float' || $type eq 'double' || $type eq 'longdouble') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$type eq "float" or $type eq "double" or $type eq "longdouble"
$type eq "float" or $type eq "double"
MC/DC0%0/3
$type eq "float" or $type eq "double" or $type eq "longdouble"
$type eq "float"
$type eq "double"
$type eq "longdouble"
Truth table0%0/4
A or B or C
A= $type eq "float"B= $type eq "double"C= $type eq "longdouble"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | ## -- floating-point types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | $opt->{cname} = long2cname($long ne '-' ? $long : $short).'_arg' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | if (!defined($opt->{cname})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | $opt->{cgiven} = cname2given($opt->{cname}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | if (!defined($opt->{cgiven})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | ▶ | $default = 0 if (!defined($default)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | # argument name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | if (!defined($opts->{arg})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | $opt->{arg} = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | $opt->{arg} =~ tr/a-z/A-Z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | return $og->wigout("option $optid: option-type '$argtype' unknown -- ignoring."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | ## -- add option information to $og | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | $og->{optshort}{$short} = $optid if ($short ne '-'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | $og->{optlong}{$long} = $optid if ($long ne '-'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | @$opt{qw(long short id)} = ($long,$short,$optid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | @$opt{qw(descr type default)} = ($descr,$type,$default); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | @$opt{qw(group ctype)} = ($og->{group},otype2ctype($opt->{type})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | $og->{opth}{$optid} = $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | #push(@{$og->{optl}}, $optid); #-- above | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | return $optid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | # $group = $og->add_group($groupname) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # + adds a group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | ▶ | sub add_group { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_group: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | my ($og,$group) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | ▶ | $og->wigout("undefined group name in add_group()") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | if (!defined($group)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | $og->{group} = $group; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | # $arg = $og->add_argument({name=>$argname,descr=>$argdescr}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | # + implicitly turns on 'unnamed' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | sub add_argument { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_argument: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | my ($og,$arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | $og->wigout("undefined argument-name in add_argument()") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | ▶ | if (!defined($arg->{name})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | $og->{unnamed} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | $arg->{descr} = '???' if (!defined($arg->{descr})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | push(@{$og->{args}},$arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | ▶ | sub set_reparse_action { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_reparse_action: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | my ($og,$action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | ▶ | if (!grep { $_ eq $action } qw(error warn clobber)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | $og->complain("unknown reparse action '$_' -- ignoring"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | return $og->{reparse_action}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | $og->{reparse_action} = $action; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # $code = $og->add_user_code($code_string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | # + add literal code section | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | ▶ | sub add_user_code { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_user_code: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | my ($og,$code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | ▶ | if (defined($og->{user_code})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $og->{user_code} .= $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | $og->{user_code} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | return $og->{user_code}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | # $rcfiles = $og->add_rcfile($filename) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # + add a degault global .rc file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | sub add_rcfile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_rcfile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | my ($og,$rcfile) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | push(@{$og->{rcfiles}}, $rcfile); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | return $og->{rcfiles}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | # Parse::Lex <-> Parse::Yapp interface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # - CONVENTIONS for yylex() sub: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | # + if the token's associated action is \&yyignore (a dummy sub), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # we don't return to the parser, but keep gobbling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # - REQUIREMENTS on yylex() sub: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # + Yapp-compatible lexing routine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | # + reads input and returns token values to the parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # + our only argument ($MyParser) is the Parse::Yapp object itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # + We return a list ($TOKENTYPE, $TOKENVAL) of the next tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # to the parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | # + on end-of-input, we should return the list ('', undef) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # undef = $og->reset(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | # + reset all parse-relevant data structures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | ▶ | sub reset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | $_[0]->{errstr} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | $_[0]->{lexer}->reset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | delete($_[0]->{parser}{USER}{hint}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # undef = yyignore() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | # + dummy function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | ▶ | sub yyignore { $_[1]; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
yyignore: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | # \&lexer_sub = $og->_yylex_sub() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | # + returns a Parse::Yapp-friendly lexer subroutine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | sub _yylex_sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_yylex_sub: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | my $og = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | my $lexer = $og->{lexer}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | my ($token,$name,$text,$bracedepth); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | return ('',undef) if ($lexer->eoi || !defined($token = $lexer->next()) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$lexer->eoi or not defined($token = $lexer->next)
MC/DC0%0/2
$lexer->eoi or not defined($token = $lexer->next)
$lexer->eoi
not defined($token = $lexer->next)
Truth table0%0/3
A or not(B)
A= $lexer->eoiB= not defined($token = $lexer->next)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | last unless (defined($token->action) && $token->action eq \&yyignore); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $token->action and $token->action eq \&yyignore
MC/DC0%0/2
defined $token->action and $token->action eq \&yyignore
defined $token->action
$token->action eq \&yyignore
Truth table0%0/3
A and B
A= defined $token->actionB= $token->action eq \&yyignore
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ($name,$text) = ($token->name,$token->text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | #print STDERR "LEXER: name=$name ; text=$text\n"; ##-- DEBUG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | ## -- handle (nested) braces | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | if ($name eq 'LBRACE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | my $bline = $lexer->line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | $lexer->start('BRACED'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | $bracedepth = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | #print STDERR "> LBRACE(bd=1)='$text'\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | ▶ | while (!$lexer->eoi && defined($token = $lexer->next())) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $lexer->eoi and defined($token = $lexer->next)
MC/DC0%0/2
not $lexer->eoi and defined($token = $lexer->next)
not $lexer->eoi
defined($token = $lexer->next)
Truth table0%0/3
not(A) and B
A= not $lexer->eoiB= defined($token = $lexer->next)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | $text .= $token->text(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | $name = $token->name(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | #print STDERR "> $name(bd=$bracedepth)='",$token->text(),"'\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | if ($name eq 'LBRACE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | $bracedepth++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | #print STDERR ("> ++(bd=$bracedepth)\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | elsif ($name eq 'RBRACE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | $bracedepth--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | #print STDERR ("> --(bd=$bracedepth)\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | if (!$bracedepth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | $lexer->end('BRACED'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | ▶ | if ($lexer->eoi || !defined($token)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$lexer->eoi or not defined $token
MC/DC0%0/2
$lexer->eoi or not defined $token
$lexer->eoi
not defined $token
Truth table0%0/3
A or not(B)
A= $lexer->eoiB= not defined $token
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | $og->wigout("EOI while parsing braced string (started at line $bline)"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | $text =~ s/^\{//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | $text =~ s/\}$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | return ('BR_STRING',$text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | return ($name,$text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | # Parsing: errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | # + Yapp error sub called as '&sub($yapp_parser)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | # + conventions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | # - allow user-hint codes for parse errors in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | # $yapp_parser->{USER}{hint} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | # - hints override default error-reporting format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | # lexer_error($lexer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | # + reports tokenization errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | ▶ | sub lexer_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lexer_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | my $og = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | my $err = $og->_gen_error('LEXER_ERROR', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | __LINE__ => $og->{lexer}->line, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | __COL__ => $og->{lexer}->pos, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | __CURTEXT__ => $_[1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | __FILE__ => (defined($og->{infile}) ? $og->{infile} : '???'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | __NAME__ => (defined($og->{name}) ? $og->{name} : __PACKAGE__ ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | (($_[1] =~ /[^$OG_ANY]/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | ? (__HINT__ => 'ILLEGAL_CHAR', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | __MATCH__ => $&) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | : (__HINT__ => 'UNKNOWN_LEXER_HINT')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | ▶ | $og->{parser}->YYAbort() if (defined($og->{parser})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | ▶ | if ($VERBOSE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | ▶ | confess(">>> ", __PACKAGE__ , "::lexer_error() called") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | die($err); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | # $errstr = $qp->_gen_error($base, \%macros) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | # + generates an error message based on the string $base | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | # + all occurrences of any of the strings which occur as keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | # of the hashref \%macros are expanded to (the translations of) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # their corresponding values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | ▶ | sub _gen_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_error: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | my ($og,$errmsg,$macros) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | $errmsg = $og->nl_xlate($errmsg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | my $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | my %nlmacros = map { ($_ => $og->nl_xlate($macros->{$_})) } keys(%$macros); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | while ($changed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | $changed = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | foreach (keys(%nlmacros)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | ▶ | if (!defined($nlmacros{$_})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | carp(__PACKAGE__ , "::_gen_error(): some goofball forgot to translate '$_'!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | ▶ | $changed = 1 if ($errmsg =~ s/$_/$nlmacros{$_}/g); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | return $errmsg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | # \&error_sub = $og->_yyerror_sub() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | # + returns a Parse::Yapp-friendly error-catching subroutine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | ▶ | sub _yyerror_sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_yyerror_sub: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | my $og = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | die($og->_gen_error((defined($_[0]->{USER}{hint}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | ? 'SEMANTIC_ERROR' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | : 'SYNTAX_ERROR'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | __NAME__ => (defined($og->{name}) ? $og->{name} : __PACKAGE__ ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | __FILE__ => (defined($og->{infile}) ? $og->{infile} : '???'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | __LINE__ => $og->{lexer}->line, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | __COL__ => $og->{lexer}->pos, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | __CURTEXT__ => $_[0]->YYCurval, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | __CURTOK__ => $og->nl_xlate($_[0]->YYCurtok), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | (defined($_[0]->{USER}{hint}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | ? (__HINT__ => $_[0]->{USER}{hint}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | : qw()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | __EXPECTED__ => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | join(', ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | ▶ | my $xl = $og->nl_xlate($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | ▶ | $xl ? $xl : qw() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | } $_[0]->YYExpect), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | # $nl_string = $og->nl_xlate($symbol) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | # + returns a natural-language string for $symbol, if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | # one is available in the package-global '%NL_XLATE' hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 0 | ▶ | sub nl_xlate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nl_xlate: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | my $nlx = \%{ref($_[0]).'::NL_XLATE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | (defined($_[1]) && exists($nlx->{$_[1]}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | ▶ | ? $nlx->{$_[1]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_[1] and exists $$nlx{$_[1]}
MC/DC0%0/2
defined $_[1] and exists $$nlx{$_[1]}
defined $_[1]
exists $$nlx{$_[1]}
Truth table0%0/3
A and B
A= defined $_[1]B= exists $$nlx{$_[1]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | : $_[1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | # older METHODS : error-reporting (still used) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | # $undef = $og->complain(@msg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | # + like carp(), but reports position in input file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | ▶ | sub complain { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
complain: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | my ($og,@msg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | print STDERR ("$og->{name}: Warning: ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | (## -- input details | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | defined($og->{infh}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | ? (## -- filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | ($og->{infile} eq '-' ? "<stdin>" : "'$og->{infile}'"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | ## -- input line-number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | ▶ | ", line ", $og->{infh}->input_line_number(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | ": ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | : qw()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | @msg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | ($msg[$#msg] !~ /\n$/s ? "\n" : qw()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | ▶ | carp(">>> ", __PACKAGE__ , "::complain() called") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | # $undef = $og->wigout(@msg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | # + like croak(), but reports position in input file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 0 | ▶ | sub wigout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wigout: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 0 | my ($og,@msg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | print STDERR ("$og->{name}: Warning: ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | (## -- input details | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | defined($og->{infh}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | ? (## -- filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | ($og->{infile} eq '-' ? "<stdin>" : "'$og->{infile}'"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | ## -- input line-number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 0 | ▶ | ", line ", $og->{infh}->input_line_number(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | ": ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | : qw()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | @msg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | ($msg[$#msg] !~ /\n$/s ? "\n" : qw()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | ▶ | confess(">>> ", __PACKAGE__ , "::wigout() called:\n") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | exit(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | # DEBUG METHODS: dump | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | # @list = $og->dump(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | # @list = $og->dump($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | ▶ | sub dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | my ($og,$name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 0 | ▶ | $name = $og->{name} if (!defined($name)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | ▶ | if ($name eq __PACKAGE__ || $name eq ref($og)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name eq __PACKAGE__ or $name eq ref $og
MC/DC0%0/2
$name eq __PACKAGE__ or $name eq ref $og
$name eq __PACKAGE__
$name eq ref $og
Truth table0%0/3
A or B
A= $name eq __PACKAGE__B= $name eq ref $og
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | $name = "$og"; ## -- default: stringify | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 0 | eval "use Data::Dumper"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | return Data::Dumper->Dump([$og],[$name]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | # NON-METHOD SUBS : utilities | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # $unquoted = dequote($txt,$quote); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | # + i.e. $string = dequote('"', '"string"'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | ▶ | sub dequote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dequote: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 0 | my ($txt,$quote) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | $txt =~ s/^$quote//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 0 | $txt =~ s/$quote$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | $txt =~ s/\\$quote/$quote/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | return $txt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | # $unquoted = bq_dequote($txt,$backquoted_string); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | # + i.e. $string = bq_dequote('`', '`string`'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | ▶ | sub bq_dequote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bq_dequote: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | my ($txt,$bquote) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | $txt =~ s/^$bquote//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 0 | $txt =~ s/$bquote$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | $txt =~ s/\\$bquote/$bquote/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | return join("", `$txt`); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | # $pod_string = podify($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 0 | ▶ | sub podify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
podify: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | ▶ | return '\'undef\'' if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 0 | $str =~ s/([\<\>])/E<$1>/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 0 | $str =~ s/E<<>/E<lt>/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 0 | $str =~ s/E<>>/E<gt>/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | #... other escapes here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | # $str_or_empty = is_string($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | # + quasi double-quoted string-checker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 0 | ▶ | sub is_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 0 | return $str =~ /^\"(?:[^\"]|(?:\\\"))*\"$/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | # string_value($string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | # + removes quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | ▶ | sub string_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
string_value: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 0 | ▶ | return undef if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | $str =~ s/^\"//s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 0 | $str =~ s/\"$//s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | # $bool = is_bool($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | # + check if string is a boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | ▶ | sub is_bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_bool: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | ▶ | return undef if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 0 | ▶ | return ($str eq 'yes' || $str eq 'no'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$str eq 'yes' || $str eq 'no'
MC/DC0%0/2
$str eq 'yes' || $str eq 'no'
$str eq 'yes'
$str eq 'no'
Truth table0%0/3
A || B
A= $str eq 'yes'B= $str eq 'no'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | # $bool_value_or_undef = bool_value($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | # + return integer boolean-value of string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | ▶ | sub bool_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bool_value: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 0 | ▶ | return undef if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 0 | ▶ | return 1 if ($str eq 'yes'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | ▶ | return 0 if ($str eq 'no'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | # $bool = is_onoff($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | # + check if string is an on/off flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 0 | ▶ | sub is_onoff { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_onoff: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 0 | ▶ | return undef if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 0 | ▶ | return ($str eq 'on' || $str eq 'off'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$str eq 'on' || $str eq 'off'
MC/DC0%0/2
$str eq 'on' || $str eq 'off'
$str eq 'on'
$str eq 'off'
Truth table0%0/3
A || B
A= $str eq 'on'B= $str eq 'off'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | # $bool_value_or_undef = onoff_value($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | # + return integer boolean-value of an on/off-string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | ▶ | sub onoff_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
onoff_value: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 0 | ▶ | return undef if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | ▶ | return 1 if ($str eq 'on'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | ▶ | return 0 if ($str eq 'off'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | # $bool = is_intstring($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | # + returns true if $str eq "$i" for some $i \in Z, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | # + hack: also accepts plain ints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 0 | ▶ | sub is_intstring { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_intstring: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 0 | ▶ | return undef if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | return $str =~ /^\s*\"?\s*(?:[+-]?)\d+\s*\"?\s*$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | # $int_or_undef = intstring_value($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | # + get integer-value from an intstring | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | ▶ | sub intstring_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
intstring_value: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 0 | ▶ | return undef if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 0 | ▶ | return $str =~ /^\s*\"?\s*(?:[+-]?)(\d+)\s*\"?\s*$/ ? $1 : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | # $bool = is_floatstring($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | # + returns true if $str eq "$f" for some $f \in R, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | # + hack: also accepts plain floats | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 0 | ▶ | sub is_floatstring { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_floatstring: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | ▶ | return undef if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | return $str =~ /^\s*\"?\s*[+-]?\d*\.?\d+\s*\"?\s*$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | # $float_or_undef = floatstring_value($str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | # + get floating-point-value from a float-string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | ▶ | sub floatstring_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
floatstring_value: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | ▶ | return undef if (!defined($str)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | ▶ | return $str =~ /^\s*\"?\s*([+-]?\d*\.?\d+)\s*\"?\s*$/ ? $1 : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | # $cname = long2cname($longname_string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | ▶ | sub long2cname { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
long2cname: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | my $long = string_value(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 0 | $long =~ s/[[:punct:]\s]/\_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 0 | return $long; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | # $cgiven = cname2given($cname) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | ▶ | sub cname2given { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cname2given: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | ▶ | return undef if (!defined($name)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 0 | ▶ | if ($name =~ /(.*)_(?:arg|flag)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | $name = $1.'_given'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | $name = $name._given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 0 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | # $ctype = otype2ctype($otype) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | ▶ | sub otype2ctype { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
otype2ctype: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | my $otype = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 0 | ▶ | return 'char *' if ($otype eq 'string'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | ▶ | return 'int' if ($otype eq 'flag' || $otype eq 'flag2'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$otype eq "flag" or $otype eq "flag2"
MC/DC0%0/2
$otype eq "flag" or $otype eq "flag2"
$otype eq "flag"
$otype eq "flag2"
Truth table0%0/3
A or B
A= $otype eq "flag"B= $otype eq "flag2"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | ▶ | return undef if ($otype eq 'funct'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 0 | return $otype; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 1 | 1; ## -- make perl happy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||