Created
January 24, 2012 12:21
-
-
Save olegwtf/1669971 to your computer and use it in GitHub Desktop.
works or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Data::Dumper; | |
use strict; | |
$a = ['google.ru', on_prepare => sub {}, timeout => 10, sub{}]; | |
print Dumper _extract_known_params($a); | |
print Dumper ($a), "-------\n"; | |
$a = ['google.ru', timeout => 10, on_prepare => sub {}, sub{}]; | |
print Dumper _extract_known_params($a); | |
print Dumper ($a), "-------\n"; | |
$a = ['google.ru', timeout => 10, sub{}]; | |
print Dumper _extract_known_params($a); | |
print Dumper ($a), "-------\n"; | |
$a = ['google.ru', on_prepare => sub{}, sub{}]; | |
print Dumper _extract_known_params($a); | |
print Dumper ($a), "-------\n"; | |
$a = ['google.ru', sub{}]; | |
print Dumper _extract_known_params($a); | |
print Dumper ($a), "-------\n"; | |
sub _extract_known_params { | |
my $args = shift; | |
my %known_params = ( | |
timeout => 1, | |
on_prepare => 1, | |
); | |
my %params; | |
eval { | |
for my $i (-2, -2) { | |
if (exists($known_params{$args->[$i-1]})) { | |
$params{$args->[$i-1]} = $args->[$i]; | |
delete $known_params{$args->[$i-1]}; | |
splice @$args, $i-1, 2; | |
} | |
else { | |
last; | |
} | |
} | |
}; | |
return \%params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment