text stringlengths 0 834k |
|---|
# if args contain closing bracket |
if (%bracket_levels) { |
# find the shortest form of the long brackets accordingly |
for (my $i = 1; $i < $max_level; $i++) { |
if (!exists $bracket_levels{$i}) { |
$bracket_level = $i; |
last; |
} |
} |
if ($bracket_level == 0) { |
$bracket_level = $max_level + 1; |
} |
return $bracket_level; |
} |
return 1; |
} |
sub quote_as_lua_str { |
my ($str) = @_; |
my $bracket_level = get_bracket_level($str); |
my $left_bracket = ""["" . ""="" x $bracket_level . ""[""; |
my $right_bracket = ""]"" . ""="" x $bracket_level . ""]""; |
return $left_bracket . $str . $right_bracket; |
} |
sub gen_lua_code_for_args { |
my ($user_args, $all_args) = @_; |
my $luasrc = ""arg = {}\n""; |
# arg[n] (n = 0) |
$luasrc .= ""arg[0] = $quoted_luafile\n""; |
# arg[n] (n > 0) |
for my $i (0 .. $#user_args) { |
my $index = $i + 1; |
my $quoted_arg = quote_as_lua_str($user_args[$i]); |
$luasrc .= ""arg[$index] = $quoted_arg\n""; |
} |
my $left_num = $#all_args - $#user_args; |
=begin cmt |
# arg[n] (n < 0) |
for my $i (0 .. $left_num - 2) { |
my $index = 0 - $left_num + $i + 1; |
my $quoted_arg = quote_as_lua_str($all_args[$i]); |
$luasrc .= ""arg[$index] = $quoted_arg\n""; |
} |
=end cmt |
=cut |
# args[n] (n = the index of resty-cli itself) |
my $index = 0 - $left_num; |
my $quoted_arg = quote_as_lua_str($0); |
$luasrc .= ""arg[$index] = $quoted_arg\n""; |
#warn $luasrc; |
return $luasrc; |
} |
sub resolve_includes ($$) { |
my ($type, $paths) = @_; |
if (!defined $cwd) { |
if ($is_win32) { |
require File::Spec; |
} else { |
$cwd = `pwd`; |
if (!$cwd || $?) { |
require Cwd; |
$cwd = Cwd::cwd(); |
} else { |
chomp $cwd; |
} |
} |
} |
my $s = ''; |
for my $path (@$paths) { |
if (!-f $path) { |
die ""ERROR: could not find $type include file '$path'""; |
} |
my $abs_path; |
if ($is_win32) { |
$abs_path = File::Spec->rel2abs($path); |
} elsif ($path =~ m{^/}) { |
$abs_path = $path; |
} else { |
$abs_path = ""$cwd/$path""; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.