Skip to content

Instantly share code, notes, and snippets.

@exodist
Created October 12, 2015 18:36
Show Gist options
  • Save exodist/18411f559c142663db33 to your computer and use it in GitHub Desktop.
Save exodist/18411f559c142663db33 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use B;
sub simple {
print "A";
print "B";
}
sub complex {
if (@_) {
print "AA";
}
else {
print "AB";
}
if (@_) {
print "BA";
}
else {
print "BB";
}
}
sub lines {
my @lines;
my $cobj = B::svref_2object($_[0]);
my $op = $cobj->START;
while ($op) {
if ($op->can('line')) {
push @lines => $op->line;
}
last unless $op->can('next');
$op = $op->next;
}
@lines = sort {$a <=> $b} @lines;
return unless @lines;
my ($start, $end) = ($lines[0], $lines[-1]);
print "$start -> $end\n";
return ($start, $end);
}
print "simple: ";
lines(\&simple);
print "complex: ";
lines(\&complex);
__END__
simple: 7 -> 12
complex: 16 -> 28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment