This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #77388] Make stacked -t work
authorFather Chrysostomos <sprout@cpan.org>
Tue, 24 Jan 2012 07:36:29 +0000 (23:36 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 24 Jan 2012 07:39:39 +0000 (23:39 -0800)
commit8db8f6b697e6f705eda3222828417099787adba4
tree9443248f2134133a9a1adda030fdab3a70a96054
parent7e68c38b607a044ee5879e316bb8a7347284ec8e
[perl #77388] Make stacked -t work

Up till now, -t was popping too much off the stack when stacked with
other filetest operators.

Since the special use of _ doesn’t apply to -t, we cannot simply have
it use _ when stacked, but instead we pass the argument down from the
previous op.

To facilitate this, the whole stacked mechanism has to change.

As before, in an expression like -r -w -x, -x  and -w are flagged
as ‘stacking’ ops (followed by another filetest), and -w and -r are
flagged as stacked (preceded by another filetest).

Stacking filetest ops no longer return a false value to the next op
when a test fails, and stacked ops no longer check the truth of the
value on the stack to determine whether to return early (if it’s
false).

The argument to the first filetest is now passed from one op to
another.  This is similar to the mechanism that overloaded objects
were already using.  Now it applies to any argument.

Since it could be false, we cannot rely on the boolean value of the
stack item.  So, stacking ops, when they return false, now traverse
the ->op_next pointers and find the op after the last stacked op.
That op is returned to the runloop.  This short-circuiting is proba-
bly faster than calling every subsequent op (a separate function call
for each).

Filetest ops other than -t continue to use the last stat buffer when
stacked, so the argument on the stack is ignored.

But if the op is preceded by nothing other than -t (where preceded
means on the right, since the ops are evaluated right-to-left), it
*does* use the argument on the stack, since -t has not set the last
stat buffer.

The new OPpFT_AFTER_t flag indicates that a stacked op is preceded by
nothing other than -t.

In ‘-e -t foo’, the -e gets the flag, but not in ‘-e -t -r foo’,
because -r will have saved the stat buffer, so -e can just use that.
doio.c
ext/B/B/Concise.pm
op.c
op.h
pp_sys.c
t/op/filetest_stack_ok.t
t/op/filetest_t.t