| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use FindBin; |
| 4 |
use lib "$FindBin::Bin/../../"; |
| 5 |
use t::scan::Util; |
| 6 |
|
| 7 |
test(<<'TEST'); # EGROSS/Lingua-PT-Conjugate-1.20/Infinitives.pm |
| 8 |
$infinitives = <<EOSTR |
| 9 |
abaetar |
| 10 |
abafar |
| 11 |
abaganhar |
| 12 |
abainhar |
| 13 |
abaixar |
| 14 |
abalan?ar |
| 15 |
abalar |
| 16 |
abalizar |
| 17 |
abalofar |
| 18 |
abalroar |
| 19 |
abanar |
| 20 |
abancar |
| 21 |
abandalhar |
| 22 |
abandar |
| 23 |
abandonar |
| 24 |
abarbar |
| 25 |
abarbatar |
| 26 |
abarcar |
| 27 |
abarracar |
| 28 |
abarrancar |
| 29 |
abarrotar |
| 30 |
abastar |
| 31 |
abastardar |
| 32 |
abastecer |
| 33 |
abastonar |
| 34 |
abatatar |
| 35 |
abater |
| 36 |
abatocar |
| 37 |
abatumar |
| 38 |
abaular |
| 39 |
aba?anar |
| 40 |
abdicar |
| 41 |
abduzir |
| 42 |
abeberar |
| 43 |
abecar |
| 44 |
abeirar |
| 45 |
abei?ar |
| 46 |
abelhar |
| 47 |
abelhudar |
| 48 |
abemolar |
| 49 |
aben?oar |
| 50 |
aberrar |
| 51 |
aberturar |
| 52 |
abesoirar |
| 53 |
abesourar |
| 54 |
abespinhar |
| 55 |
abetumar |
| 56 |
abicar |
| 57 |
abichornar |
| 58 |
abiscatar |
| 59 |
abiscoitar |
| 60 |
abismar |
| 61 |
abisonhar |
| 62 |
abispar |
| 63 |
abjudicar |
| 64 |
abjurar |
| 65 |
abjurgar |
| 66 |
ablegar |
| 67 |
abnegar |
| 68 |
abobar |
| 69 |
abocanhar |
| 70 |
abocar |
| 71 |
aboiar |
| 72 |
abojar |
| 73 |
aboletar |
| 74 |
abolir |
| 75 |
abominar |
| 76 |
abonan?ar |
| 77 |
abonar |
| 78 |
abordar |
| 79 |
aborrecer |
| 80 |
abortar |
| 81 |
abotecar |
| 82 |
abotoar |
| 83 |
abrancar |
| 84 |
abrandar |
| 85 |
abrandecer |
| 86 |
abranger |
| 87 |
abrasar |
| 88 |
abrasileirar |
| 89 |
abrasilianar |
| 90 |
abra?ar |
| 91 |
abrejar |
| 92 |
abrenunciar |
| 93 |
abreviar |
| 94 |
abrigar |
| 95 |
abrilhantar |
| 96 |
abrir |
| 97 |
abrochar |
| 98 |
abrogar |
| 99 |
abrolhar |
| 100 |
abroquelar |
| 101 |
abrumar |
| 102 |
abrutalhar |
| 103 |
absceder |
| 104 |
abscindir |
| 105 |
absconder |
| 106 |
absolver |
| 107 |
absonar |
| 108 |
absorver |
| 109 |
abster |
| 110 |
abstrair |
| 111 |
abufelar |
| 112 |
abular |
| 113 |
abundar |
| 114 |
aburguesar |
| 115 |
abusar |
| 116 |
acabar |
| 117 |
acaboclar |
| 118 |
acabrunhar |
| 119 |
acachapar |
| 120 |
acachoar |
| 121 |
academizar |
| 122 |
acadimar |
| 123 |
acafajestar |
| 124 |
acaipirar |
| 125 |
acai?arar |
| 126 |
acalcanhar |
| 127 |
acalcar |
| 128 |
acalentar |
| 129 |
acalmar |
| 130 |
acalorar |
| 131 |
acal?ar |
| 132 |
acamar |
| 133 |
acamaradar |
| 134 |
acampar |
| 135 |
acanalhar |
| 136 |
acanastrar |
| 137 |
acanavear |
| 138 |
acanhalar |
| 139 |
acanhar |
| 140 |
acanivetar |
| 141 |
acanteirar |
| 142 |
acantonar |
| 143 |
acapachar |
| 144 |
acapangar |
| 145 |
acapelar |
| 146 |
acapoeirar |
| 147 |
acapuchar |
| 148 |
acardumar |
| 149 |
acarear |
| 150 |
acariciar |
| 151 |
acarinhar |
| 152 |
acarneirar |
| 153 |
acarrancar |
| 154 |
acarretar |
| 155 |
acartar |
| 156 |
acasalar |
| 157 |
acasernar |
| 158 |
acastanhar |
| 159 |
acastelar |
| 160 |
acatar |
| 161 |
acatitar |
| 162 |
acatruzar |
| 163 |
acaudilhar |
| 164 |
acautelar |
| 165 |
acavalar |
| 166 |
aca?apar |
| 167 |
accionar |
| 168 |
accorrer |
| 169 |
aceder |
| 170 |
aceitar |
| 171 |
acelerar |
| 172 |
acenar |
| 173 |
acender |
| 174 |
acentuar |
| 175 |
acepilhar |
| 176 |
acerar |
| 177 |
acerbar |
| 178 |
acercar |
| 179 |
acertar |
| 180 |
acervar |
| 181 |
acessar |
| 182 |
acetinar |
| 183 |
achacar |
| 184 |
achanar |
| 185 |
achaparrar |
| 186 |
achar |
| 187 |
achatar |
| 188 |
achavascar |
| 189 |
achegar |
| 190 |
achicar |
| 191 |
achincalhar |
| 192 |
achinelar |
| 193 |
achinesar |
| 194 |
acicatar |
| 195 |
acicular |
| 196 |
acidar |
| 197 |
acidentar |
| 198 |
acidificar |
| 199 |
acidular |
| 200 |
acinzar |
| 201 |
acinzentar |
| 202 |
acioinar |
| 203 |
acionar |
| 204 |
acirrar |
| 205 |
acitrinar |
| 206 |
acizentar |
| 207 |
aclamar |
| 208 |
aclarar |
| 209 |
aclimar |
| 210 |
aclimatar |
| 211 |
aclimatizar |
| 212 |
acobardar |
| 213 |
acobertar |
| 214 |
acocar |
| 215 |
acochar |
| 216 |
acocorar |
| 217 |
acogular |
| 218 |
acoimar |
| 219 |
acoitar |
| 220 |
acolchetar |
| 221 |
acolchoar |
| 222 |
acolher |
| 223 |
acolherar |
| 224 |
acomadrar |
| 225 |
acometer |
| 226 |
acomodar |
| 227 |
acompadrar |
| 228 |
acompanhar |
| 229 |
acompassar |
| 230 |
acompridar |
| 231 |
aconchegar |
| 232 |
acondicionar |
| 233 |
acondimentar |
| 234 |
aconselhar |
| 235 |
aconsoantar |
| 236 |
acontecer |
| 237 |
acoplar |
| 238 |
acopular |
| 239 |
acoquinar |
| 240 |
acordar |
| 241 |
acoronhar |
| 242 |
acorrentar |
| 243 |
acorrer |
| 244 |
acossar |
| 245 |
acostar |
| 246 |
acostumar |
| 247 |
acotovelar |
| 248 |
acovardar |
| 249 |
acovilhar |
| 250 |
acravar |
| 251 |
acreditar |
| 252 |
acrescentar |
| 253 |
acrescer |
| 254 |
acrian?ar |
| 255 |
acrisolar |
| 256 |
acromatizar |
| 257 |
activar |
| 258 |
actualizar |
| 259 |
actuar |
| 260 |
acudir |
| 261 |
acumular |
| 262 |
acurar |
| 263 |
acurralar |
| 264 |
acurvar |
| 265 |
acusar |
| 266 |
acutangular |
| 267 |
acutilar |
| 268 |
adagiar |
| 269 |
adamascar |
| 270 |
adaptar |
| 271 |
adegar |
| 272 |
adejar |
| 273 |
adelga?ar |
| 274 |
adensar |
| 275 |
adentar |
| 276 |
adentrar |
| 277 |
adequar |
| 278 |
aderir |
| 279 |
adernar |
| 280 |
adestrar |
| 281 |
adeusar |
| 282 |
adiamantar |
| 283 |
adiantar |
| 284 |
adiar |
| 285 |
adicionar |
| 286 |
adietar |
| 287 |
adir |
| 288 |
aditar |
| 289 |
adivinhar |
| 290 |
adjectivar |
| 291 |
adjetivar |
| 292 |
adjudicar |
| 293 |
adjurar |
| 294 |
adjutorar |
| 295 |
adjuvar |
| 296 |
adminicular |
| 297 |
administrar |
| 298 |
admirar |
| 299 |
admitir |
| 300 |
admoestar |
| 301 |
adocicar |
| 302 |
adoecer |
| 303 |
adoentar |
| 304 |
adoestar |
| 305 |
adoidar |
| 306 |
adolescer |
| 307 |
adomar |
| 308 |
adonar |
| 309 |
adonisar |
| 310 |
adoptar |
| 311 |
adorar |
| 312 |
adormecer |
| 313 |
adormentar |
| 314 |
adornar |
| 315 |
adotar |
| 316 |
ado?ar |
| 317 |
adquirir |
| 318 |
adscrever |
| 319 |
adstringir |
| 320 |
adubar |
| 321 |
adular |
| 322 |
adulterar |
| 323 |
adumbrar |
| 324 |
adunar |
| 325 |
aduzir |
| 326 |
adverbializar |
| 327 |
adverbiar |
| 328 |
adverbizar |
| 329 |
adversar |
| 330 |
advertir |
| 331 |
advir |
| 332 |
advogar |
| 333 |
afadigar |
| 334 |
afagar |
| 335 |
afainar |
| 336 |
afamar |
| 337 |
afanar |
| 338 |
afastar |
| 339 |
afazer |
| 340 |
afectar |
| 341 |
afei?oar |
| 342 |
afeminar |
| 343 |
aferir |
| 344 |
aferrar |
| 345 |
aferroar |
| 346 |
aferrolhar |
| 347 |
aferventar |
| 348 |
afervorar |
| 349 |
afetar |
| 350 |
afiambrar |
| 351 |
afian?ar |
| 352 |
afiar |
| 353 |
afidalgar |
| 354 |
afigurar |
| 355 |
afilar |
| 356 |
afilhar |
| 357 |
afiliar |
| 358 |
afinar |
| 359 |
afincar |
| 360 |
afirmar |
| 361 |
afivelar |
| 362 |
afixar |
| 363 |
aflar |
| 364 |
aflautar |
| 365 |
afleumar |
| 366 |
afligir |
| 367 |
aflorar |
| 368 |
afluir |
| 369 |
afobar |
| 370 |
afocinhar |
| 371 |
afofar |
| 372 |
afogar |
| 373 |
afoguear |
| 374 |
afoitar |
| 375 |
afolar |
| 376 |
afolhar |
| 377 |
afolozar |
| 378 |
aforar |
| 379 |
aformosar |
| 380 |
aformosear |
| 381 |
aforquilhar |
| 382 |
aforrar |
| 383 |
afortalezar |
| 384 |
afortunar |
| 385 |
afracar |
| 386 |
afrancesar |
| 387 |
afranzinar |
| 388 |
afrechar |
| 389 |
afreguesar |
| 390 |
afrentar |
| 391 |
afretar |
| 392 |
africanar |
| 393 |
africanizar |
| 394 |
afronhar |
| 395 |
afrontar |
| 396 |
afrouxar |
| 397 |
afugentar |
| 398 |
afumar |
| 399 |
afundar |
| 400 |
afunilar |
| 401 |
agachar |
| 402 |
agadanhar |
| 403 |
agaitar |
| 404 |
agarotar |
| 405 |
EOSTR |
| 406 |
; |
| 407 |
1 ; |
| 408 |
TEST |
| 409 |
|
| 410 |
test(<<'TEST'); # ISTEEL/HTMLTMPL-1.34/HTMLTMPL.pm |
| 411 |
sub dumpAll() |
| 412 |
{ |
| 413 |
print << "EOHTML"; |
| 414 |
Content-type: text/html |
| 415 |
|
| 416 |
<html><head><title>Dump of tokens and values</title></head> |
| 417 |
<body bgcolor=beige> |
| 418 |
<h3 align=center>Dump of tokens and values</h3> |
| 419 |
<p> |
| 420 |
<table border=1 align=center> |
| 421 |
<tr align=center><th bgcolor=lightblue>Token</th><th colspan=2 bgcolor=lightblue>Value</th></tr> |
| 422 |
EOHTML |
| 423 |
dumpit(@_); |
| 424 |
|
| 425 |
print "</table></body></html>"; |
| 426 |
} |
| 427 |
|
| 428 |
sub dumpit() |
| 429 |
{ |
| 430 |
my ($self, $block) = @_; |
| 431 |
|
| 432 |
if (defined $block) |
| 433 |
{ |
| 434 |
$self = \%$block if (defined $block); |
| 435 |
} |
| 436 |
|
| 437 |
my $repeating = $self->{'_C__REPEAT__'}; |
| 438 |
} |
| 439 |
TEST |
| 440 |
|
| 441 |
test(<<'TEST'); # GOMOR/Net-Packet-2.22/Packet/TCP.pm |
| 442 |
my $offX2Flags = ($self->off << 12) | (0x0f00 & ($self->x2 << 8)) |
| 443 |
| (0x00ff & $self->flags); |
| 444 |
|
| 445 |
my $phpkt; |
| 446 |
# Handle checksumming with DescL2&3 |
| 447 |
if ($frame->l3) { |
| 448 |
if ($frame->l3->isIpv4) { |
| 449 |
$phpkt = $self->SUPER::pack('a4a4CCn', |
| 450 |
inetAton($frame->l3->src), |
| 451 |
inetAton($frame->l3->dst), |
| 452 |
0, |
| 453 |
$frame->l3->protocol, |
| 454 |
$frame->l3->getPayloadLength, |
| 455 |
) or return undef; |
| 456 |
} |
| 457 |
elsif ($frame->l3->isIpv6) { |
| 458 |
$phpkt = $self->SUPER::pack('a*a*NnCC', |
| 459 |
inet6Aton($frame->l3->src), |
| 460 |
inet6Aton($frame->l3->dst), |
| 461 |
$frame->l3->payloadLength, |
| 462 |
0, |
| 463 |
0, |
| 464 |
$frame->l3->nextHeader, |
| 465 |
) or return undef; |
| 466 |
} |
| 467 |
} |
| 468 |
# Handle checksumming with DescL4 |
| 469 |
else { |
| 470 |
my $totalLength = $self->getLength; |
| 471 |
$totalLength += $frame->l7->getLength if $frame->l7; |
| 472 |
|
| 473 |
|
| 474 |
if ($env->desc->isFamilyIpv4) { |
| 475 |
$phpkt = $self->SUPER::pack('a4a4CCn', |
| 476 |
inetAton($env->ip), |
| 477 |
inetAton($env->desc->target), |
| 478 |
0, |
| 479 |
$env->desc->protocol, |
| 480 |
$totalLength, |
| 481 |
) or return undef; |
| 482 |
} |
| 483 |
elsif ($env->desc->isFamilyIpv6) { |
| 484 |
$phpkt = $self->SUPER::pack('a*a*NnCC', |
| 485 |
inet6Aton($env->ip6), |
| 486 |
inet6Aton($env->desc->target), |
| 487 |
$totalLength, |
| 488 |
0, |
| 489 |
0, |
| 490 |
$env->desc->protocol, |
| 491 |
) or return undef; |
| 492 |
} |
| 493 |
} |
| 494 |
TEST |
| 495 |
|
| 496 |
test(<<'TEST'); # FEDOROV/File-Stat-Bits-1.01/Bits.pm |
| 497 |
sub dev_join |
| 498 |
{ |
| 499 |
my ($major, $minor) = @_; |
| 500 |
|
| 501 |
package File::Stat::Bits::dirty; |
| 502 |
|
| 503 |
if ( defined MAJOR_SHIFT ) |
| 504 |
{ |
| 505 |
return |
| 506 |
(($major << MAJOR_SHIFT) & MAJOR_MASK) | |
| 507 |
(($minor << MINOR_SHIFT) & MINOR_MASK); |
| 508 |
} |
| 509 |
else |
| 510 |
{ |
| 511 |
return undef; |
| 512 |
} |
| 513 |
} |
| 514 |
TEST |
| 515 |
|
| 516 |
test(<<'TEST'); # GAAL/Perl6-Signature-0.04/lib/Perl6/Signature.pm |
| 517 |
package Perl6::Signature; |
| 518 |
|
| 519 |
use warnings; |
| 520 |
|
| 521 |
use Parse::RecDescent; |
| 522 |
use Text::Balanced; |
| 523 |
use Perl6::Signature::Val; |
| 524 |
|
| 525 |
our $VERSION = '0.04'; |
| 526 |
|
| 527 |
#$::RD_TRACE = 1; |
| 528 |
$::RD_HINT = 1; |
| 529 |
|
| 530 |
our $SIGNATURE_GRAMMAR = << '#\'END'; |
| 531 |
#\ |
| 532 |
{ |
| 533 |
use Text::Balanced qw(extract_bracketed); |
| 534 |
use Carp qw(croak); |
| 535 |
} |
| 536 |
|
| 537 |
Sig: Sig_colon | Sig_nocolon |
| 538 |
|
| 539 |
Sig_colon: ':' Sig_nocolon |
| 540 |
|
| 541 |
Sig_nocolon: '(' Sigbody ')' |
| 542 |
{ $item{Sigbody} } |
| 543 |
|
| 544 |
Sigbody: Sigbody_inv | Sigbody_noinv |
| 545 |
|
| 546 |
Sigbody_inv: Invocant <skip:'\s*'> ':' Sigbody_noinv |
| 547 |
{ |
| 548 |
my $sig = $item{Sigbody_noinv}; |
| 549 |
die "invocant cannot be optional" unless $item{Invocant}->{required}; |
| 550 |
$sig->s_invocant( $item{Invocant}->{param} ); |
| 551 |
$return = $sig; |
| 552 |
} |
| 553 |
|
| 554 |
Sigbody_noinv: Param(s? /,/) |
| 555 |
{ |
| 556 |
my @params = @{ $item{'Param(s?)'} }; |
| 557 |
my @slurpies = map { $_->{param} } grep { $_->{slurpy} } @params; |
| 558 |
my @nonslurpies = grep { !$_->{slurpy} } @params; |
| 559 |
my @positionals = grep { $_->{style} eq 'positional' } @nonslurpies; |
| 560 |
my @named = grep { $_->{style} eq 'named' } @nonslurpies; |
| 561 |
|
| 562 |
my $seen_optional; |
| 563 |
my $requiredPositionalCount = 0; |
| 564 |
|
| 565 |
# calculate requiredPositionalCount, and make sure we don't have |
| 566 |
# :($optional?, $required!) -- that's invalid. |
| 567 |
for my $param (@positionals) { |
| 568 |
$seen_optional++ if ! $param->{required}; |
| 569 |
die "can't place required positional after an optional one" if |
| 570 |
$param->{required} && $seen_optional; |
| 571 |
$requiredPositionalCount++ if ! $seen_optional; |
| 572 |
} |
| 573 |
|
| 574 |
my %slurpies = map { $_->p_sigil => $_ } @slurpies; |
| 575 |
|
| 576 |
my ( $slurpy_array, $slurpy_hash ) = ( @slurpies{qw(@ %)} ); |
| 577 |
|
| 578 |
croak "Only one slurpy of every type is allowed" if keys %slurpies != @slurpies; |
| 579 |
|
| 580 |
my $sig = Perl6::Signature::Val::Sig->new |
| 581 |
( s_requiredPositionalCount => $requiredPositionalCount |
| 582 |
, s_positionalList => [ map { $_->{param} } @positionals ] |
| 583 |
, s_namedList => [ map { $_->{param} } @named ] |
| 584 |
, s_requiredNames => { map { $_->{param}->p_label => 1 } grep { $_->{required} } @named } |
| 585 |
, ( $slurpy_array ? ( s_slurpyArray => $slurpy_array ) : () ), |
| 586 |
, ( $slurpy_hash ? ( s_slurpyHash => $slurpy_hash ) : () ), |
| 587 |
); |
| 588 |
$return = $sig; |
| 589 |
} |
| 590 |
|
| 591 |
Invocant: Param |
| 592 |
|
| 593 |
Param: ParamType(s? /\|/) |
| 594 |
SlurpynessModifier(?) |
| 595 |
ParamIdentifier <skip:''> |
| 596 |
OptionalityModifier(?) |
| 597 |
<skip:'\s*'> |
| 598 |
Unpacking(?) |
| 599 |
DefaultValueSpec(?) |
| 600 |
<skip:'\s+'> |
| 601 |
Attrib(s?) |
| 602 |
<skip:'\s*'> |
| 603 |
Constraint(s?) |
| 604 |
{ |
| 605 |
my ($variable, $label, $style) = |
| 606 |
@{$item{ParamIdentifier}}{qw/variable label style/}; |
| 607 |
|
| 608 |
my ($hasAccess, $isRef, $isContext, $isLazy, @slots); |
| 609 |
# unfortunately, we can't use a hash and delete from it: |
| 610 |
# "is ro is rw" means "is rw". (Or maybe, a parse error.) |
| 611 |
ATTR: for (@{ $item{'Attrib(s?)'} }) { |
| 612 |
/^(ro|rw|copy)$/ && do { $hasAccess = $_; next ATTR }; |
| 613 |
/^ref$/ && do { $isRef = 1; next ATTR }; |
| 614 |
/^context$/ && do { $isContext = 1; next ATTR }; |
| 615 |
/^lazy$/ && do { $isLazy = 1; next ATTR }; |
| 616 |
push @slots, $_; |
| 617 |
} |
| 618 |
|
| 619 |
my $param = Perl6::Signature::Val::SigParam->new |
| 620 |
( p_types => $item{'ParamType(s?)'} |
| 621 |
, p_variable => $variable |
| 622 |
, p_label => $label |
| 623 |
, ($item{'Unpacking(?)'} ? (p_unpacking => $item{'Unpacking(?)'}->[0]) : ()) |
| 624 |
, (@{ $item{'DefaultValueSpec(?)'} } ? |
| 625 |
(p_default => $item{'DefaultValueSpec(?)'}->[0]) : ()) |
| 626 |
, (@{ $item{'Constraint(s?)'} } ? |
| 627 |
(p_constraints => [ @{ $item{'Constraint(s?)'} } ]) : ()) |
| 628 |
, ( $hasAccess ? ( p_hasAccess => $hasAccess ) : () ), |
| 629 |
, p_isRef => $isRef |
| 630 |
, p_isContext => $isContext |
| 631 |
, p_isLazy => $isLazy |
| 632 |
, p_slots => { map { $_ => 1 } @slots } |
| 633 |
# "is foo<42>" not supported yet. |
| 634 |
); |
| 635 |
my $slurpy = 1 == @{ $item{'SlurpynessModifier(?)'} }; |
| 636 |
my $optionality = $item{'OptionalityModifier(?)'}->[0] || ''; |
| 637 |
my $optional = scalar @{ $item{'DefaultValueSpec(?)'} }; |
| 638 |
die "required parameter can't have default value" if |
| 639 |
$optional && $optionality eq '!'; |
| 640 |
$optional = 1 if $style eq 'named' && $optionality ne '!'; |
| 641 |
$optional = 1 if $optionality eq '?'; |
| 642 |
|
| 643 |
$return = { param => $param |
| 644 |
, required => !$optional |
| 645 |
, style => $style |
| 646 |
, slurpy => $slurpy |
| 647 |
}; |
| 648 |
} |
| 649 |
|
| 650 |
ParamType: /[a-zA-Z]\w+/ |
| 651 |
|
| 652 |
ParamIdentifier: ParamIdentifier_positional |
| 653 |
| ParamIdentifier_named |
| 654 |
|
| 655 |
# Perl 6 allows placeholder parameters, e.g. :($) - sub of arity 1 (scalar). |
| 656 |
ParamIdentifier_positional: Sigil <skip:''> Label(?) |
| 657 |
{ |
| 658 |
my $label = @{ $item{'Label(?)'} } ? $item{'Label(?)'}->[0] : ''; |
| 659 |
$return = { variable => $item{Sigil} . $label |
| 660 |
, label => $label |
| 661 |
, style => 'positional' |
| 662 |
}; |
| 663 |
} |
| 664 |
|
| 665 |
# TODO: L<S06/"Multiple name wrappings may be given">, whoa. |
| 666 |
ParamIdentifier_named: |
| 667 |
':' <skip:''> Label ParamIdentifier_named_variablename |
| 668 |
{ |
| 669 |
$return = { variable => $item{'ParamIdentifier_named_variablename'} |
| 670 |
, label => $item{Label} |
| 671 |
, style => 'named' |
| 672 |
}; |
| 673 |
} |
| 674 |
| ':' <skip:''> Sigil Label |
| 675 |
{ |
| 676 |
$return = { variable => $item{Sigil} . $item{Label} |
| 677 |
, label => $item{Label} |
| 678 |
, style => 'named' |
| 679 |
}; |
| 680 |
} |
| 681 |
|
| 682 |
ParamIdentifier_named_variablename: '(' <perl_variable> ')' |
| 683 |
{ $return = $item[2]; 1; } |
| 684 |
|
| 685 |
OptionalityModifier: /[!?]/ |
| 686 |
|
| 687 |
SlurpynessModifier: /\*/ |
| 688 |
|
| 689 |
Unpacking: Sig |
| 690 |
|
| 691 |
Constraint: 'where' <perl_codeblock> |
| 692 |
|
| 693 |
# default values are _unevaluated_. |
| 694 |
DefaultValueSpec: '=' ValueOrSomeStabAtOne |
| 695 |
|
| 696 |
ValueOrSomeStabAtOne: Value_numberLiteral |
| 697 |
| Value_acceptableQuotelike |
| 698 |
| Value_variable |
| 699 |
| Value_looksBalanced |
| 700 |
| Value_looksClosure |
| 701 |
|
| 702 |
# perlfaq4 ftw |
| 703 |
Value_numberLiteral: /([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?/ # float |
| 704 |
| /-?(?:\d+(?:\.\d*)?|\.\d+)/ # decimal |
| 705 |
| /-?\d+\.?\d*/ # real |
| 706 |
| /[+-]?\d+/ # +/- integer |
| 707 |
| /-?\d+/ # integer |
| 708 |
| /\d+/ # whole number |
| 709 |
| /0x[0-9a-fA-F]+/ # hexadecimal |
| 710 |
| /0b[01]+/ # binary |
| 711 |
# note that octals will be captured by the "whole number" |
| 712 |
# production. Our consumer will have to eval this (we don't |
| 713 |
# want to do it for them because of roundtripping. But maybe |
| 714 |
# we need annotation nodes anyway? |
| 715 |
|
| 716 |
Value_acceptableQuotelike: <perl_quotelike> |
| 717 |
{ |
| 718 |
my $op = $item[1]->[0]; # q, qq etc. |
| 719 |
my %whitelist = map { $_ => 1 } qw(q qq qw qr); # TODO: lift this up |
| 720 |
die "rejected quotelike operator: $op" unless $whitelist{$op}; |
| 721 |
$return = join "", @{ $item[0] }; |
| 722 |
1; |
| 723 |
} |
| 724 |
|
| 725 |
Value_variable: <perl_variable> |
| 726 |
|
| 727 |
Value_looksBalanced: { extract_bracketed($text, '()') } |
| 728 |
| { extract_bracketed($text, '[]') } |
| 729 |
| { extract_bracketed($text, '{}') } |
| 730 |
|
| 731 |
Value_looksClosure: 'sub' <perl_codeblock> |
| 732 |
|
| 733 |
Attrib: 'is' Label |
| 734 |
|
| 735 |
Sigil: /[\$\@\%]/ |
| 736 |
|
| 737 |
Label: /\w+/ |
| 738 |
|
| 739 |
# This one is a bummer: we don't want to provide a full parser for |
| 740 |
# Perl expressions here. If we are called in the context of Devel::Declare, |
| 741 |
# perhaps we can get a reference back to the real parser? Otherwise, we're |
| 742 |
# stuck with doing some half-assed parsing that would preclude e.g. |
| 743 |
# :($pi = 22/7) |
| 744 |
Literal: /\S+/ |
| 745 |
#'END |
| 746 |
|
| 747 |
my $parser = Parse::RecDescent->new($SIGNATURE_GRAMMAR) || die "GRAMMAR NO WORKY *CWY* *CWY*"; |
| 748 |
|
| 749 |
sub parse { |
| 750 |
my($self, $sig_str) = @_; |
| 751 |
|
| 752 |
my $res = $parser->Sig($sig_str); |
| 753 |
|
| 754 |
die "Unparsable signature" |
| 755 |
unless $res; |
| 756 |
|
| 757 |
return $res; |
| 758 |
} |
| 759 |
|
| 760 |
# These are my favorite debugging tools. Share and enjoy. |
| 761 |
#sub ::Y { require YAML::Syck; YAML::Syck::Dump(@_) } |
| 762 |
#sub ::YY { require Carp; Carp::confess(::Y(@_)) } |
| 763 |
|
| 764 |
6; |
| 765 |
|
| 766 |
__END__ |
| 767 |
=head1 NAME |
| 768 |
|
| 769 |
Perl6::Signature - Parse, query, and pretty-print Perl 6 signatures |
| 770 |
|
| 771 |
=head1 SYNOPSIS |
| 772 |
|
| 773 |
use Perl6::Signature; |
| 774 |
|
| 775 |
my $sig = Perl6::Signature->parse( |
| 776 |
':($self: $x, Int $y = 42 where { $_ % 2 == 0 }, :$z is copy)'); |
| 777 |
|
| 778 |
print $sig->s_requiredPositionalCount; # 1 |
| 779 |
print $sig->s_positionalList->[0]->p_label # "x" |
| 780 |
print $sig->s_namedList->[0]->p_hasAccess; # "copy" |
| 781 |
|
| 782 |
print $sig->to_string; |
| 783 |
# ":($self: $x, Int $y = 42 where { $_ % 2 == 0 }, :$z is copy)" |
| 784 |
|
| 785 |
=head1 DESCRIPTION |
| 786 |
|
| 787 |
I<Alpha release - everything here is subject to change> |
| 788 |
|
| 789 |
B<Perl6::Signature> models routine signatures as specified in Synopsis 6 of |
| 790 |
the Perl 6 documentation. These signatures offer a rich language for |
| 791 |
expressing type constraints, default values, and the optionality (among other |
| 792 |
things) of routine parameters. |
| 793 |
|
| 794 |
Included is a parser for the Signature language, accessors and convenience |
| 795 |
methods for querying Signature objects, and a pretty-printer for producing |
| 796 |
their canonical textual representation. |
| 797 |
|
| 798 |
=head1 MODULE LAYOUT OVERVIEW |
| 799 |
|
| 800 |
B<Perl6::Signature> contains a B<Parse::RecDescent>-based parser for |
| 801 |
signatures. |
| 802 |
|
| 803 |
B<Perl6::Signature::Val> is our local base class for Perl 6 values. |
| 804 |
It doesn't do anything interested in itself, but if this distribution is |
| 805 |
bridged to another Perl 6-modeling distribution, this could be the first |
| 806 |
insertion point for glue methods. The next two modules subclass it. |
| 807 |
|
| 808 |
B<Perl6::Signature::Val::Sig> and B<Perl6::Signature::Val::SigParam> |
| 809 |
model full signatures and their consituent parameters. This is where you |
| 810 |
go to quiery and pretty-print your parsed objects. |
| 811 |
|
| 812 |
=head1 FUNCTIONS |
| 813 |
|
| 814 |
=head2 Perl6::Signature |
| 815 |
|
| 816 |
=over 4 |
| 817 |
|
| 818 |
=item Perl6::Signature->parse(STRING) |
| 819 |
|
| 820 |
Parse a well-formed signature specification into a |
| 821 |
B<Perl6::Signature::Val::Sig> object. Returns undef on failure, and |
| 822 |
in some cases can die. (This needs to be regularized.) |
| 823 |
|
| 824 |
CAVEAT #1: we do "best effort" parsing for default values. Simple |
| 825 |
literals are okay; complex expressions may not be. |
| 826 |
|
| 827 |
CAVEAT #2: default value specifications are not evaluated by |
| 828 |
B<Perl6::Signature>, not-in-scope errors are not raised, and constant |
| 829 |
folding is not performed. There may be semantic implications to this. |
| 830 |
|
| 831 |
CAVEAT #3: we similarly do "best effort" to parse dynamic constraints |
| 832 |
(C<"where {....}"> blocks). Funky code might well fail to parse correctly. |
| 833 |
|
| 834 |
=back |
| 835 |
|
| 836 |
=head2 Perl6::Signature::Val::Sig |
| 837 |
|
| 838 |
=over 4 |
| 839 |
|
| 840 |
=item $sig->to_string |
| 841 |
|
| 842 |
Pretty-print a Sig object into canonical textual form. |
| 843 |
|
| 844 |
"Canonical form" means regualar whitespace, implicit "!" on mandatory |
| 845 |
positional parameters, impicit "?" on optional named parameters, and |
| 846 |
so on. Code from dynamic constraints is reproduced verbatim. |
| 847 |
|
| 848 |
=item has 's_invocant' => (is => 'rw', isa => 'Perl6::Signature::Val::SigParam', required => 0); |
| 849 |
|
| 850 |
=item has 's_requiredPositionalCount' => (is => 'rw', isa => 'Int'); |
| 851 |
|
| 852 |
=item has 's_requiredNames' => (is => 'rw', isa => 'HashRef'); # Set of names |
| 853 |
|
| 854 |
=item has 's_positionalList' => (is => 'rw', isa => 'ArrayRef[Perl6::Signature::Val::SigParam]'); |
| 855 |
|
| 856 |
=item has 's_namedList' => (is => 'rw', isa => 'ArrayRef[Perl6::Signature::Val::SigParam]'); |
| 857 |
|
| 858 |
=item has 's_slurpyScalarList' => (is => 'rw', isa => 'ArrayRef', required => 0); |
| 859 |
|
| 860 |
=item has 's_slurpyArray' => (is => 'rw', isa => 'Perl6::Signature::Val::SigParam', required => 0); |
| 861 |
|
| 862 |
=item has 's_slurpyHash' => (is => 'rw', isa => 'Perl6::Signature::Val::SigParam', required => 0); |
| 863 |
|
| 864 |
=item has 's_slurpyCode' => (is => 'rw', isa => 'Perl6::Signature::Val::SigParam', required => 0); |
| 865 |
|
| 866 |
=item has 's_slurpyCapture' => (is => 'rw', isa => 'Perl6::Signature::Val::SigParam', required => 0); |
| 867 |
|
| 868 |
=back |
| 869 |
|
| 870 |
=head2 Perl6::Signature::Val::SigParam |
| 871 |
|
| 872 |
=over 4 |
| 873 |
|
| 874 |
=item $param->to_string(%args) |
| 875 |
|
| 876 |
Pretty-print a SigParam object into canonical form. Note that a SigParam |
| 877 |
doesn't know whether it is required or optional; nor whether it is positional |
| 878 |
or named. This must be supplied by the Sig container. |
| 879 |
|
| 880 |
=item has 'p_variable' => (is => 'rw', isa => 'Str'); |
| 881 |
|
| 882 |
=item has 'p_types' => (is => 'rw', isa => 'ArrayRef'); # of types |
| 883 |
|
| 884 |
=item has 'p_constraints' => (is => 'rw', isa => 'ArrayRef'); # of code |
| 885 |
|
| 886 |
=item has 'p_unpacking' => (is => 'rw', isa => 'Perl6::Signature::Val::Sig|Undef', required => 0); |
| 887 |
|
| 888 |
=item has 'p_default' => (is => 'rw', required => 0); |
| 889 |
|
| 890 |
=item has 'p_label' => (is => 'rw', isa => 'Str'); |
| 891 |
|
| 892 |
=item has 'p_slots' => (is => 'rw', isa => 'HashRef'); |
| 893 |
|
| 894 |
=item has 'p_hasAccess' => (is => 'rw', ); # ro/rw/copy |
| 895 |
|
| 896 |
=item has 'p_isRef' => (is => 'rw', isa => 'Bool'); |
| 897 |
|
| 898 |
=item has 'p_isContext' => (is => 'rw', isa => 'Bool'); |
| 899 |
|
| 900 |
=item has 'p_isLazy' => (is => 'rw', isa => 'Bool'); |
| 901 |
|
| 902 |
=back |
| 903 |
|
| 904 |
=head1 SEE ALSO |
| 905 |
|
| 906 |
=over 4 |
| 907 |
|
| 908 |
=item L<http://perlcabal.org/syn/S06.html#Parameters_and_arguments> |
| 909 |
|
| 910 |
=item L<Moose> |
| 911 |
|
| 912 |
=item L<Parse::RecDescent> |
| 913 |
|
| 914 |
=back |
| 915 |
|
| 916 |
=head1 AUTHORS |
| 917 |
|
| 918 |
Gaal Yahas, C<< <gaal at forum2.org> >> |
| 919 |
|
| 920 |
Contributions by: |
| 921 |
|
| 922 |
Yuval Kogman, CC< <[email protected]> >> |
| 923 |
|
| 924 |
Florian Ragwitz, CC< <[email protected]> >> |
| 925 |
|
| 926 |
=head1 BUGS |
| 927 |
|
| 928 |
Please report any bugs or feature requests to |
| 929 |
C<bug-perl6-signature at rt.cpan.org>, or through the web interface at |
| 930 |
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Perl6-Signature>. |
| 931 |
I will be notified, and then you'll automatically be notified of progress on |
| 932 |
your bug as I make changes. |
| 933 |
|
| 934 |
=head1 SUPPORT |
| 935 |
|
| 936 |
You can find documentation for this module with the perldoc command. |
| 937 |
|
| 938 |
perldoc Perl6::Signature |
| 939 |
|
| 940 |
You can also contact the maintainer at the address above or look for information at: |
| 941 |
|
| 942 |
=over 4 |
| 943 |
|
| 944 |
=item * AnnoCPAN: Annotated CPAN documentation |
| 945 |
|
| 946 |
L<http://annocpan.org/dist/Perl6-Signature/> |
| 947 |
|
| 948 |
=item * Search CPAN |
| 949 |
|
| 950 |
L<http://search.cpan.org/dist/Perl6-Signature/> |
| 951 |
|
| 952 |
=item * Source repository |
| 953 |
|
| 954 |
L<https://github.com/gaal/perl6-signature/> |
| 955 |
|
| 956 |
=back |
| 957 |
|
| 958 |
=head1 COPYRIGHT (The "MIT" License) |
| 959 |
|
| 960 |
Copyright 2008 Gaal Yahas. |
| 961 |
|
| 962 |
Permission is hereby granted, free of charge, to any person obtaining a |
| 963 |
copy of this software and associated documentation files (the "Software"), |
| 964 |
to deal in the Software without restriction, including without limitation |
| 965 |
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 966 |
and/or sell copies of the Software, and to permit persons to whom the |
| 967 |
Software is furnished to do so, subject to the following conditions: |
| 968 |
|
| 969 |
The above copyright notice and this permission notice shall be included |
| 970 |
in all copies or substantial portions of the Software. |
| 971 |
|
| 972 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 973 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 974 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 975 |
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 976 |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 977 |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 978 |
OTHER DEALINGS IN THE SOFTWARE. |
| 979 |
|
| 980 |
=cut |
| 981 |
TEST |
| 982 |
|
| 983 |
test(<<'TEST'); # JENDA/CGI-Authent-0.2.1/Authent.pm |
| 984 |
sub between ($) { |
| 985 |
unless (isbetween(@_)) { |
| 986 |
$header =~ s/401.*?\n/403 Forbidden\x0D\x0A/m; |
| 987 |
$msg = <<"*END*"; |
| 988 |
<HTML> |
| 989 |
<HEAD><TITLE>Temporarily forbidden</TITLE></HEAD> |
| 990 |
<BODY> |
| 991 |
<h1>Temporarily forbidden</h1> |
| 992 |
This resource is available only at $_[0]. Please come later. |
| 993 |
</BODY> |
| 994 |
</HTML> |
| 995 |
*END* |
| 996 |
} |
| 997 |
return $res; |
| 998 |
} |
| 999 |
TEST |
| 1000 |
|
| 1001 |
test(<<'TEST'); # PFEIFFER/SQL-Steno-0.3.2/lib/SQL/Steno.pm |
| 1002 |
print <<\HELP; |
| 1003 |
All entries are single line unless \\wrapped at 1st bol and last eol\\ or continued.\ |
| 1004 |
Queries have the form: {{!}/regexp/{i}}{=}query |
| 1005 |
The query has lots of short-hands expanded, unless it is prefixed by the optional =. |
| 1006 |
The fields joined with '~' are grepped if regexp is given, case-insensitively if i is given. |
| 1007 |
|
| 1008 |
??query Only shows massaged query. |
| 1009 |
!perl-code Runs perl-code. |
| 1010 |
>file Next query's output to file. In csv or yaml format if filename has that suffix. |
| 1011 |
|
| 1012 |
Query has the form {select|update|insert|delete}{fieldlist};tablelist{;clause} or set ... |
| 1013 |
'select' is prepended if none of these initial keywords. |
| 1014 |
fieldlist defaults to '*', also if Query starts with '#'. |
| 1015 |
';' is alternately replaced by 'from' and 'where'. |
| 1016 |
|
| 1017 |
Abbreviations, more help with ?&{abbrev}, ?:{abbrev}, ?\{abbrev}, ?#{abbrev}, ?.{abbrev}, ?{abbrev}( |
| 1018 |
&{Perl code}... # only at bol, if it returns undef then skip, else prepend to ... |
| 1019 |
&query $1;$2;... # only at bol |
| 1020 |
&query($1;$2;...)... # only at bol, only replace upto ) |
| 1021 |
:macro |
| 1022 |
:\quote(arg,...) # split, quote & join (?\ alone needs trailing space, because \ at end continues) |
| 1023 |
:{Perl code} # dynamic macro |
| 1024 |
#table #table#t |
| 1025 |
.column .column.c # for any table recognized in statement |
| 1026 |
function( |
| 1027 |
|
| 1028 |
Characters \t\n\r get masked in output, \r\n as \R. |
| 1029 |
Date or time 0000-00-00 -> 0000- 1970-01-01 -> 1970- 00:00:00 -> 00: 23:59:59 -> 24: |
| 1030 |
HELP |
| 1031 |
TEST |
| 1032 |
|
| 1033 |
done_testing; |