ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf/match.pm
(Generate patch)

Comparing deliantra/server/lib/cf/match.pm (file contents):
Revision 1.13 by root, Sun Oct 11 23:51:47 2009 UTC vs.
Revision 1.33 by root, Tue Oct 12 20:15:48 2010 UTC

1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3#
4# Copyright (©) 2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5#
6# Deliantra is free software: you can redistribute it and/or modify it under
7# the terms of the Affero GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or (at your
9# option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the Affero GNU General Public License
17# and the GNU General Public License along with this program. If not, see
18# <http://www.gnu.org/licenses/>.
19#
20# The authors can be reached via e-mail to <support@deliantra.net>
21#
22
1=head1 NAME 23=head1 NAME
2 24
3cf::match - object matching language 25cf::match - object matching language
4 26
5=head1 DESCRIPTION 27=head1 DESCRIPTION
66 condition in inv of originator 88 condition in inv of originator
67 89
68Once the final set of context objects has been established, each object 90Once the final set of context objects has been established, each object
69is matched against the C<condition>. 91is matched against the C<condition>.
70 92
93It is possible to chain modifiers from right-to-left, so this example
94would start with the originator, take it's inventory, find all inventory
95items which are potions, looks into their inventory, and then finds all
96spells.
97
98 type=SPELL in type=POTION in inv of originator
99
71Sometimes the server is only interested in knowing whether I<anything> 100Sometimes the server is only interested in knowing whether I<anything>
72matches, and sometimes the server is interested in I<all> objects that 101matches, and sometimes the server is interested in I<all> objects that
73match. 102match.
74 103
75=head2 OPERATORS 104=head2 OPERATORS
77=over 4 106=over 4
78 107
79=item and, or, not, () 108=item and, or, not, ()
80 109
81Conditions can be combined with C<and> or C<or> to build larger 110Conditions can be combined with C<and> or C<or> to build larger
82expressions. C<not> negates the expression, and parentheses can be used to 111expressions. C<not> negates the condition, and parentheses can be used to
83group conditions. 112override operator precedence and execute submatches.
113
114Not that C<not> only negates a condition and not the whole match
115expressions, thus
116
117 not applied in inv
118
119is true if there is I<any> non-applied object in the inventory. To negate
120a whole match, you have to use a sub-match: To check whether there is
121I<no> applied object in someones inventory, write this:
122
123 not (applied in inv)
84 124
85Example: match applied weapons. 125Example: match applied weapons.
86 126
87 applied type=WEAPON 127 applied type=WEAPON
88 128
89Example: match horns or rods. 129Example: match horns or rods.
90 130
91 type=HORN or type=ROD 131 type=HORN or type=ROD
132
133Example: see if the originator is a player.
134
135 type=PLAYER of originator
92 136
93=item in ... 137=item in ...
94 138
95The in operator takes the context set and modifies it in various ways. As 139The in operator takes the context set and modifies it in various ways. As
96a less technical description, think of the C<in> as being a I<look into> 140a less technical description, think of the C<in> as being a I<look into>
110 154
111=item in env 155=item in env
112 156
113Replaces all objects by their containing object, if they have one. 157Replaces all objects by their containing object, if they have one.
114 158
159=item in arch
160
161Replaces all objects by their archetypes.
162
115=item in map 163=item in map
116 164
117Replaces all objects by the objects that are on the same mapspace as them. 165Replaces all objects by the objects that are on the same mapspace as them.
118 166
167=item in head
168
169Replaces all objects by their head objects.
170
119=item in <cond> 171=item in <condition>
120 172
121Finds all context objects matching the condition, and then puts their 173Finds all context objects matching the condition, and then puts their
122inventories into the context set. 174inventories into the context set.
123 175
124Note that C<in inv> is simply a special case of an C<< in <cond> >> that 176Note that C<in inv> is simply a special case of an C<< in <condition> >> that
125matches any object. 177matches any object.
126 178
127Example: find all spells inside potions inside the inventory of the context 179Example: find all spells inside potions inside the inventory of the context
128object(s). 180object(s).
129 181
136 188
137Example: check if the context object I<is> a spell, or I<contains> a spell. 189Example: check if the context object I<is> a spell, or I<contains> a spell.
138 190
139 type=SPELL also in inv 191 type=SPELL also in inv
140 192
141=item deep in ... 193=item also deep in ...
142 194
143Repeats the operation as many times as possible. This can be used to 195Repeats the operation as many times as possible. This can be used to
144recursively look into objects. 196recursively look into objects.
145 197
146=item also deep in ... 198So for example, C<also deep in inv> means to take the inventory of all
199objects, taking their inventories, and so on, and adding all these objects
200to the context set.
147 201
148C<also> and C<deep> can be combined. 202Similarly, C<also deep in env> means to take the environment object, their
203environemnt object and so on.
149 204
150Example: check if there are any unpaid items in an inventory, 205Example: check if there are any unpaid items in an inventory,
151or in the inventories of the inventory objects, and so on. 206or in the inventories of the inventory objects, and so on.
152 207
153 unpaid also deep in inv 208 unpaid also deep in inv
174Starts with the default object - this is the object passed to the match to 229Starts with the default object - this is the object passed to the match to
175match against by default. Matches have an explicit C<of object> appended, 230match against by default. Matches have an explicit C<of object> appended,
176but submatches start at the current object, and in this case C<of object> 231but submatches start at the current object, and in this case C<of object>
177can be used to start at the original object once more. 232can be used to start at the original object once more.
178 233
234=item of self
235
236Starts with the object initiating/asking for the match - this is basically
237always the object that the match expression is attached to.
238
179=item of source 239=item of source
180 240
181Starts with the I<source> object - this object is sometimes passed to 241Starts with the I<source> object - this object is sometimes passed to
182matches and represents the object that is the source of the action, such 242matches and represents the object that is the source of the action, such
183as a rod or a potion when it is applied. Often, the I<source> is the same 243as a rod or a potion when it is applied. Often, the I<source> is the same
190the original initiator of an action, most commonly a player or monster. 250the original initiator of an action, most commonly a player or monster.
191 251
192This object is often identical to the I<source> (e.g. when a player casts 252This object is often identical to the I<source> (e.g. when a player casts
193a spell, the player is both source and originator). 253a spell, the player is both source and originator).
194 254
195=item of self
196
197Starts with the object initiating/asking for the match - this is basically
198always the object that the match expression is attached to.
199
200=back 255=back
201 256
202=head2 EXPRESSIONS 257=head2 EXPRESSIONS
203 258
204Expressions used in conditions usually consist of simple boolean checks 259Expressions used in conditions usually consist of simple boolean checks
213 268
214=item scalar object attributes 269=item scalar object attributes
215 270
216Object attributes that consist of a single value (C<name>, C<title>, 271Object attributes that consist of a single value (C<name>, C<title>,
217C<value> and so on) can be specified by simply using their name, in which 272C<value> and so on) can be specified by simply using their name, in which
218acse their corresponding value is used. 273case their corresponding value is used.
219 274
220=item array objects attributes 275=item array objects attributes
221 276
222The C<resist> array can be accessed by specifying C<< resist [ ATNR_type ] 277The C<resist> array can be accessed by specifying C<< resist [ ATNR_type ]
223>>. 278>>.
227 resist[ATNR_ACID] > 30 282 resist[ATNR_ACID] > 30
228 283
229=item functions 284=item functions
230 285
231Some additional functions with or without arguments in parentheses are 286Some additional functions with or without arguments in parentheses are
232available. 287available. They are documented in their own section, below.
233 288
234=item { BLOCK } 289=item { BLOCK }
235 290
236You can specify perl code to execute by putting it inside curly 291You can specify perl code to execute by putting it inside curly
237braces. The last expression evaluated inside will become the result. 292braces. The last expression evaluated inside will become the result.
272=item any 327=item any
273 328
274This simply evaluates to true, and simply makes matching I<any> object a 329This simply evaluates to true, and simply makes matching I<any> object a
275bit easier to read. 330bit easier to read.
276 331
332=item none
333
334This simply evaluates to false, and simply makes matching I<never> a bit
335easier to read.
336
337=item archname
338
339The same as C<< { $_->arch->archname } >> - the archetype name is commonly
340used to match items, so this shortcut is provided.
341
342=item resist_xxx
343
344Resistancy values such as C<resist_physical>, C<resist_magic>,
345C<resists_fire> etc. are directly available (but can also be accessed via
346array syntax, i.e. C<resists[ATNR_FIRE]>).
347
348=item body_xxx_info and body_xxx_used
349
350Every body location (e.g. C<body_neck_info>, C<body_arm_used> etc.) can
351be accessed via these functions (these are aliases to more cumbersome C<< {
352$_->slot_info (body_xxx) } >> and C<slot_used> method calls).
353
354Example: (e.g. on a door) match only players that have no arms.
355
356 match type=PLAYER and body_arm_info=0
357
277=item has(condition) 358=item has(condition)
278 359
279True iff the object has a matching inventory object. 360True iff the object has a matching inventory object.
280 361
281=item count(match) 362=item count(match)
282 363
283Number of matching objects - the context object for the C<match> is the 364Number of matching objects - the context object for the C<match> is the
284currently tested object - you can override this with an C<in object> for 365currently tested object - you can override this with an C<in object> for
285example. 366example.
286 367
287=item match(match)
288
289An independent match - semantics like C<count>, except it only matters
290whether the match finds any object (which is faster).
291
292=item dump 368=item dump()
293 369
294Dumps the object to the server log when executed, and evaluates to true. 370Dumps the object to the server log when executed, and evaluates to true.
295 371
296Note that logical operations are short-circuiting, so this only dumps 372Note that logical operations are short-circuiting, so this only dumps
297potions: 373potions:
298 374
299 type=POTION and dump 375 type=POTION and dump()
300 376
301=back 377=back
302 378
303=head2 GRAMMAR 379=head2 GRAMMAR
304 380
310 386
311 match = chain 387 match = chain
312 | chain 'of' root 388 | chain 'of' root
313 root = 'object' | 'self' | 'source' | 'originator' 389 root = 'object' | 'self' | 'source' | 'originator'
314 chain = condition 390 chain = condition
315 | chain also deep 'in' set 391 | chain also deep 'in' modifier
316 also = nothing | 'also' 392 also = nothing | 'also'
317 deep = nothing | 'deep' 393 deep = nothing | 'deep'
318 set = 'inv' | 'env' | 'map' 394 modifier ='inv' | 'env' | 'arch' | 'map' | 'head'
319 395
320 empty = 396 nothing =
321 397
322 # boolean matching condition 398 # boolean matching condition
323 399
324 condition = factor 400 condition = factor
325 | factor 'and'? cond 401 | factor 'and'? condition
326 | factor 'or' cond 402 | factor 'or' condition
327 403
328 factor = 'not' factor 404 factor = 'not' factor
329 | '(' cond ')' 405 | '(' match ')'
330 | expr 406 | expr
331 | expr operator constant 407 | expr operator constant
332 408
333 operator = '=' | '==' | '!=' | '<' | '<=' | '>' | '>=' 409 operator = '=' | '==' | '!=' | '<' | '<=' | '>' | '>='
334 410
335 expr = flag 411 expr = flag
336 | sattr 412 | sattr
337 | aattr '[' <constant> ']' 413 | aattr '[' <constant> ']'
414 | 'stat.' statattr
338 | special 415 | special
339 | func '(' args ')' 416 | func '(' args ')'
340 | '{' perl code block '}' 417 | '{' perl code block '}'
341 418
342 func = <any function name> 419 func = <any function name>
343 sattr = <any scalar object attribute> 420 sattr = <any scalar object attribute>
344 aattr = <any array object attribute> 421 aattr = <any array object attribute>
345 flag = <any object flag> 422 flag = <any object flag>
423 statattr = <any stat attribute: exp, food, str, dex, hp, maxhp...>
346 special = <any ()-less "function"> 424 special = <any ()-less "function">
347 425
348 constant = <number> | '"' <string> '"' | <uppercase cf::XXX name> 426 constant = <number> | '"' <string> '"' | <uppercase cf::XXX name>
349 args = <depends on function> 427 args = <depends on function>
350 428
362 440
363use common::sense; 441use common::sense;
364 442
365use List::Util (); 443use List::Util ();
366 444
367# parser state
368# $_ # string to be parsed
369our $all; # find all, or just the first matching object
370
371{ 445{
372 package cf::match::exec; 446 package cf::match::exec;
373 447
374 use List::Util qw(first); 448 use List::Util qw(first);
375 449
379 453
380 sub ws { 454 sub ws {
381 /\G\s+/gc; 455 /\G\s+/gc;
382 } 456 }
383 457
458 sub condition ();
459 sub match ($$);
460
384 our %func = ( 461 our %func = (
385 has => sub { 462 has => sub {
386 'first { ' . &condition . ' } $_->inv' 463 'first { ' . condition . ' } $_->inv'
387 }, 464 },
388 count => sub { 465 count => sub {
389 local $all = 1;
390 '(scalar ' . &match ('$_') . ')' 466 '(scalar ' . (match 1, '$_') . ')'
391 },
392 match => sub {
393 local $all = 0;
394 '(scalar ' . &match ('$_') . ')'
395 },
396 );
397
398 our %special = (
399 any => sub {
400 1
401 }, 467 },
402 dump => sub { 468 dump => sub {
403 'do { 469 'do {
404 warn "cf::match::match dump:\n" 470 warn "cf::match::match dump:\n"
405 . "self: " . eval { $self->name } . "\n" 471 . "self: " . eval { $self->name } . "\n"
407 1 473 1
408 }'; 474 }';
409 }, 475 },
410 ); 476 );
411 477
478 our %special = (
479 any => sub {
480 1
481 },
482 none => sub {
483 0
484 },
485 archname => sub {
486 '$_->arch->archname'
487 },
488 );
489
490 # resist_xxx
491 for my $atnr (0 .. cf::NROFATTACKS - 1) {
492 $special{"resist_" . cf::attacktype_name ($atnr)} = sub { "\$_->resist ($atnr)" };
493 }
494
495 # body_xxx_info and _used
496 for my $slot (0 .. cf::NUM_BODY_LOCATIONS - 1) {
497 my $name = cf::object::slot_name $slot;
498
499 $special{"body_$name\_info"} = sub { "\$_->slot_info ($slot)" };
500 $special{"body_$name\_used"} = sub { "\$_->slot_used ($slot)" };
501 }
502
412 sub constant { 503 sub constant {
413 ws; 504 ws;
414 505
415 return $1 if /\G([\-\+0-9\.]+)/gc; 506 return $1 if /\G([\-\+0-9\.]+)/gc;
416 return "cf::$1" if /\G([A-Z0-9_]+)/gc; 507 return "cf::$1" if /\G([A-Z0-9_]+)/gc;
422 } 513 }
423 514
424 our $flag = $cf::REFLECT{object}{flags}; 515 our $flag = $cf::REFLECT{object}{flags};
425 our $sattr = $cf::REFLECT{object}{scalars}; 516 our $sattr = $cf::REFLECT{object}{scalars};
426 our $aattr = $cf::REFLECT{object}{arrays}; 517 our $aattr = $cf::REFLECT{object}{arrays};
518 our $lattr = $cf::REFLECT{living}{scalars};
427 519
428 sub expr { 520 sub expr {
429 # ws done by factor 521 # ws done by factor
430 my $res; 522 my $res;
431 523
434 526
435 my $expr = $1; 527 my $expr = $1;
436 528
437 $res .= $expr =~ /\{([^;]+)\}/ ? $1 : "do $expr"; 529 $res .= $expr =~ /\{([^;]+)\}/ ? $1 : "do $expr";
438 530
531 } elsif (/\Gstats\.([A-Za-z0-9_]+)/gc) {
532
533 if (exists $lattr->{$1}) {
534 $res .= "\$_->stats->$1";
535 } elsif (exists $lattr->{"\u$1"}) {
536 $res .= "\$_->stats->\u$1";
537 } else {
538 die "living statistic name expected (str, pow, hp, sp...)\n";
539 }
540
439 } elsif (/\G([A-Za-z0-9_]+)/gc) { 541 } elsif (/\G([A-Za-z0-9_]+)/gc) {
440 542
441 if (my $func = $func{$1}) { 543 if (my $func = $func{$1}) {
442 /\G\s*\(/gc 544 /\G\s*\(/gc
443 or die "'(' expected after function name\n"; 545 or die "'(' expected after function name\n";
471 } else { 573 } else {
472 $res .= constant; 574 $res .= constant;
473 } 575 }
474 576
475 } else { 577 } else {
578 Carp::cluck;#d#
476 die "expr expected\n"; 579 die "expr expected\n";
477 } 580 }
478 581
479 $res 582 $res
480 } 583 }
497 $res .= "!"; 600 $res .= "!";
498 } 601 }
499 602
500 if (/\G\(/gc) { 603 if (/\G\(/gc) {
501 # () 604 # ()
502 $res .= &condition; 605
503 ws; 606 $res .= '(' . (match 0, '$_') . ')';
607
504 /\G\)/gc or die "')' expected\n"; 608 /\G\s*\)/gc or die "closing ')' expected\n";
505 609
506 } else { 610 } else {
507 my $expr = expr; 611 my $expr = expr;
508 612
509 $res .= $expr; 613 $res .= $expr;
520 } 624 }
521 625
522 "($res)" 626 "($res)"
523 } 627 }
524 628
525 sub condition { 629 sub condition () {
526 my $res = factor; 630 my $res = factor;
527 631
528 while () { 632 while () {
529 ws; 633 ws;
530 634
531 # first check some stop-symbols, so we don't have to backtrack 635 # first check some stop-symbols, so we don't have to backtrack
532 if (/\G(?=also\b|deep\b|in\b|of\b\)|$)/gc) { 636 if (/\G(?=also\b|deep\b|in\b|of\b|\)|\z)/gc) {
637 pos = pos; # argh. the misop hits again. again. again. again. you die.
533 last; 638 last;
534 639
535 } elsif (/\Gor\b/gc) { 640 } elsif (/\Gor\b/gc) {
536 $res .= " || "; 641 $res .= " || ";
537 642
543 } 648 }
544 649
545 $res 650 $res
546 } 651 }
547 652
548 sub match { 653 sub match ($$) {
549 my $default = shift; 654 my ($wantarray, $defctx) = @_;
550 655
656 my $res = condition;
657
658 # if nothing follows, we have a simple condition, so
659 # optimise a comon case.
660 if ($defctx eq '$_' and /\G\s*(?=\)|$)/gc) {
661 return $wantarray
662 ? "$res ? \$_ : ()"
663 : $res;
664 }
665
551 my $res = ($all ? " grep { " : " first {") . condition . " }"; 666 $res = ($wantarray ? " grep { " : " first { ") . $res . "}";
552 667
553 while () { 668 while () {
554 ws; 669 ws;
555 670
556 my $also = /\Galso\s+/gc + 0; 671 my $also = /\Galso\s+/gc + 0;
557 my $deep = /\Gdeep\s+/gc + 0; 672 my $deep = /\Gdeep\s+/gc + 0;
558 673
559 if (/\Gin\s+/gc) { 674 if (/\Gin\s+/gc) {
560 my $expand; 675 my $expand;
561 676
562 if (/\G(inv|env|map)\b/gc) { 677 if (/\G(inv|env|map|arch|head)\b/gc) {
563 if ($1 eq "inv") { 678 if ($1 eq "inv") {
564 $expand = "map \$_->inv,"; 679 $expand = "map \$_->inv,";
565 } elsif ($1 eq "env") { 680 } elsif ($1 eq "env") {
566 $expand = "map \$_->env // (),"; 681 $expand = "map \$_->env // (),";
682 } elsif ($1 eq "head") {
683 $expand = "map \$_->head,";
684 $deep = 0; # infinite loop otherwise
685 } elsif ($1 eq "arch") {
686 $expand = "map \$_->arch,";
687 $deep = 0; # infinite loop otherwise
567 } elsif ($1 eq "map") { 688 } elsif ($1 eq "map") {
568 $expand = "map \$_->map->at (\$_->x, \$_->y),"; 689 $expand = "map \$_->map->at (\$_->x, \$_->y),";
690 $deep = 0; # infinite loop otherwise
569 } 691 }
570 } else { 692 } else {
571 $expand = "map \$_->inv, grep { " . condition . " }"; 693 $expand = "map \$_->inv, grep { " . condition . " }";
572 } 694 }
573 695
581 $res .= " (\@res, \@_)\n" 703 $res .= " (\@res, \@_)\n"
582 . "}"; 704 . "}";
583 } else { 705 } else {
584 $res .= " $expand"; 706 $res .= " $expand";
585 } 707 }
708 } else {
709
586 } elsif (/\Gof\s+(self|object|source|originator)\b/gc) { 710 if (/\Gof\s+(self|object|source|originator)\b/gc) {
587 $also || $deep 711 $also || $deep
588 and die "neither 'also' nor 'deep' can be used with 'of'\n"; 712 and die "neither 'also' nor 'deep' can be used with 'of'\n";
589 713
590 if ($1 eq "self") { 714 if ($1 eq "self") {
591 return "$res \$self // ()"; 715 return "$res \$self // ()";
592 } elsif ($1 eq "object") { 716 } elsif ($1 eq "object") {
593 return "$res \$object"; 717 return "$res \$object";
594 } elsif ($1 eq "source") { 718 } elsif ($1 eq "source") {
595 return "$res \$source // ()"; 719 return "$res \$source // ()";
596 } elsif ($1 eq "originator") { 720 } elsif ($1 eq "originator") {
597 return "$res \$originator // \$source // ()"; 721 return "$res \$originator // \$source // ()";
722 }
723 } else {
724 return "$res $defctx";
598 } 725 }
599 } else {
600 return "$res $default";
601 } 726 }
602 } 727 }
603 } 728 }
604} 729}
605 730
606sub parse($;$) { 731sub parse($$) { # wantarray, matchexpr
607 local $_ = shift;
608 local $all = shift;
609
610 my $res; 732 my $res;
611 733
734 local $_ = $_[1];
735
612 eval { 736 eval {
613 $res = cf::match::parser::match "\$object"; 737 $res = cf::match::parser::match $_[0], "\$object";
614 738
615 /\G\s*$/gc 739 /\G$/gc
616 or die "unexpected trailing characters after match\n"; 740 or die "unexpected trailing characters after match\n";
617 }; 741 };
618 742
619 if ($@) { 743 if ($@) {
620 my $ctx = 20; 744 my $ctx = 20;
627 751
628 $res 752 $res
629} 753}
630 754
631if (0) {#d# 755if (0) {#d#
632 die parse 'applied', 1; 756 die parse 1, 'type=PLAYER and body_arm_info=0';
633 exit 0; 757 exit 0;
634} 758}
635 759
636=item cf::match::match $match, $object[, $self[, $source[, $originator]]]
637
638Compiles (and caches) the C<$match> expression and matches it against
639the C<$object>. C<$self> should be the object initiating the match (or
640C<undef>), C<$source> should be the actor/source and C<$originator> the
641object that initiated the action (such as the player). C<$originator>
642defaults to C<$source> when not given.
643
644In list context it finds and returns all matching objects, in scalar
645context only a true or false value.
646
647=cut
648
649our %CACHE; 760our %CACHE;
650 761
651sub compile($$) { 762sub compile($$) {
652 my ($match, $all) = @_; 763 my ($wantarray, $match) = @_;
653 my $expr = parse $match, $all; 764 my $expr = parse $wantarray, $match;
654 warn "MATCH DEBUG $match,$all => $expr\n";#d# 765# warn "MATCH DEBUG $match,$wantarray => $expr\n";#d#
655 $expr = eval " 766 $expr = eval "
656 package cf::match::exec; 767 package cf::match::exec;
657 sub { 768 sub {
658 my (\$object, \$self, \$source, \$originator) = \@_; 769 my (\$object, \$self, \$source, \$originator) = \@_;
659 $expr 770 $expr
662 die if $@; 773 die if $@;
663 774
664 $expr 775 $expr
665} 776}
666 777
778=item cf::match::match $match, $object[, $self[, $source[, $originator]]]
779
780Compiles (and caches) the C<$match> expression and matches it against
781the C<$object>. C<$self> should be the object initiating the match (or
782C<undef>), C<$source> should be the actor/source and C<$originator> the
783object that initiated the action (such as the player). C<$originator>
784defaults to C<$source> when not given.
785
786In list context it finds and returns all matching objects, in scalar
787context only a true or false value.
788
789=cut
790
667sub match($$;$$$) { 791sub match($$;$$$) {
668 my $match = shift; 792 my $match = shift;
669 my $all = wantarray+0; 793 my $wantarray = wantarray+0;
670 794
671 &{ 795 &{
672 $CACHE{"$all$match"} ||= compile $match, $all 796 $CACHE{"$wantarray$match"} ||= compile $wantarray, $match
673 } 797 }
674} 798}
799
800our $CACHE_CLEARER = AE::timer 3600, 3600, sub {
801 %CACHE = ();
802};
675 803
676#d# $::schmorp=cf::player::find "schmorp"& 804#d# $::schmorp=cf::player::find "schmorp"&
677#d# cf::match::match '', $::schmorp->ob 805#d# cf::match::match '', $::schmorp->ob
678 806
679 807

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines