| 1 | package B::Utils1::OP; | ||
| 2 | |||
| 3 | 1 | require 5.006; | |
| 4 | 1 | ▶ | use B::Utils1 (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | our @ISA = 'Exporter'; | |
| 7 | 1 | require Exporter; | |
| 8 | 1 | our $VERSION = '1.05'; | |
| 9 | 1 | our @EXPORT = qw(parent_op return_op); | |
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | B::Utils1::OP - op related utility functions for perl | ||
| 14 | |||
| 15 | =head1 SYNOPSIS | ||
| 16 | |||
| 17 | use B::Utils1::OP qw(parent_op return_op); | ||
| 18 | sub foo { | ||
| 19 | my $pop = parent_op(0); | ||
| 20 | my $rop = return_op(0); | ||
| 21 | } | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | sub foo { | ||
| 26 | dothis(1); | ||
| 27 | find_things(); | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | has the following optree: | ||
| 32 | |||
| 33 | d <1> leavesub[1 ref] K/REFC,1 ->(end) | ||
| 34 | - <@> lineseq KP ->d | ||
| 35 | 1 <;> nextstate(main -371 bah.pl:8) v/2 ->2 | ||
| 36 | 5 <1> entersub[t2] vKS/TARG,3 ->6 | ||
| 37 | - <1> ex-list K ->5 | ||
| 38 | 2 <0> pushmark s ->3 | ||
| 39 | 3 <$> const[IV 1] sM ->4 | ||
| 40 | - <1> ex-rv2cv sK/3 ->- | ||
| 41 | 4 <#> gv[*dothis] s ->5 | ||
| 42 | 6 <;> nextstate(main -371 bah.pl:9) v/2 ->7 | ||
| 43 | |||
| 44 | 9 <1> entersub[t4] vKS/TARG,3 ->a | ||
| 45 | - <1> ex-list K ->9 | ||
| 46 | 7 <0> pushmark s ->8 | ||
| 47 | - <1> ex-rv2cv sK/3 ->- | ||
| 48 | 8 <#> gv[*find_things] s/EARLYCV ->9 | ||
| 49 | |||
| 50 | a <;> nextstate(main -371 bah.pl:10) v/2 ->b | ||
| 51 | c <@> return K ->d | ||
| 52 | b <0> pushmark s ->c | ||
| 53 | |||
| 54 | The C<find_things> in C<foo> is called in the C<entersub> in #9. If | ||
| 55 | you call C<parent_op> function with level 0, you get the C<nextstate> | ||
| 56 | op that is before the entersub, which is #6. And C<return_op> gives | ||
| 57 | you the next op that the caller is returning to, in this case, the | ||
| 58 | C<nextstate> in #a. | ||
| 59 | |||
| 60 | =head2 EXPORTED PERL FUNCTIONS | ||
| 61 | |||
| 62 | =over | ||
| 63 | |||
| 64 | =item parent_op($lv) | ||
| 65 | |||
| 66 | In runtime, returns the L<B::OP> object whose next is the C<entersub> of the current context up level C<$lv> | ||
| 67 | |||
| 68 | =item return_op($lv) | ||
| 69 | |||
| 70 | In runtime, returns the L<B::OP> object that the current context is returning to at level C<$lv> | ||
| 71 | |||
| 72 | =back | ||
| 73 | |||
| 74 | =head1 AUTHORS | ||
| 75 | |||
| 76 | Chia-liang Kao E<lt>clkao@clkao.orgE<gt> | ||
| 77 | |||
| 78 | =head1 COPYRIGHT | ||
| 79 | |||
| 80 | Copyright 2008 by Chia-liang Kao | ||
| 81 | |||
| 82 | This program is free software; you can redistribute it and/or modify it | ||
| 83 | under the same terms as Perl itself. | ||
| 84 | |||
| 85 | See L<http://www.perl.com/perl/misc/Artistic.html> | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | 1 | 1; | |