[Moscow.pm] Indirect call

Ruslan Zakirov ruz на bestpractical.com
Чт Дек 13 10:08:13 PST 2012


2012/12/13 Mons Anderson <mons на cpan.org>:
> Наткнулся на весьма забавный способ сделать indirect вызов.
>
> $ perl -Mstrict -M5.010
> sub Content::headers { say "@_"; return 456 }
> sub call(@) { say "call: @_" }
> call( headers { "Content" => 123 } "new","arg" );
>
> Попробуйте предсказать что будет выведено, а потом запустите )

Это как-то попахивает багой, по идее должно превратиться в:

call(  ({ "Content" => 123 })->headers( "new","arg" ) );

И развалиться. Я бы зарепортил.

Из следующего вывода видно, что фигурные скобки парсятся как scope и
соответственно "возвращаемые" значения просто кладутся на стек.

perl -MO=Concise -E 'headers { "Content" => 123 } "new","arg";'
c  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 48 -e:1) v:%,{,469764096 ->3
b     <1> entersub[t1] vKS/TARG ->c
3        <0> pushmark s ->4
-        <@> scope lKM ->8
-           <0> ex-nextstate v ->4
7           <@> list lKM ->8
4              <0> pushmark sM ->5
5              <$> const(PV "Content") sM ->6
6              <$> const(IV 123) sM ->7
8        <$> const(PV "new") sM ->9
9        <$> const(PV "arg") sM ->a
a        <$> method_named(PV "headers") ->b
-e syntax OK


> --
> Best wishes,
> Vladimir V. Perepelitsa aka Mons Anderson
> <inthrax на gmail.com>, <mons на cpan.org>
> http://github.com/Mons
>
> --
> Moscow.pm mailing list
> moscow-pm на pm.org | http://moscow.pm.org
>



-- 
Best regards, Ruslan.


Подробная информация о списке рассылки Moscow-pm