App-short
view release on metacpan or search on metacpan
lib/App/short.pm view on Meta::CPAN
use experimental 'smartmatch';
unless (PRELOAD) { require Cwd; } #PRELOAD
unless (PRELOAD) { require File::Spec; } #PRELOAD
my %args = @_;
my $res = _validate(\%args);
return $res unless $res->[0] == 200;
my $S = $args{short_dir};
my $L = $args{long_dir};
return [404, "No such long name '$args{long}'"]
unless (-d "$L/$args{long}");
return [412, "Short name '$args{short}' already exists"]
if (-l "$S/$args{short}");
symlink(File::Spec->abs2rel(
Cwd::abs_path("$L/$args{long}"),
Cwd::abs_path($S),
), "$S/$args{short}") or return [500, "Can't create symlink: $!"];
[200, "OK"];
lib/App/short.pm view on Meta::CPAN
return $res unless $res->[0] == 200;
my $S = $args{short_dir};
my $envres = Perinci::Object::envresmulti();
for my $s (@{ $args{short} }) {
my $path = "$S/$s";
if (!(-l $path)) {
$envres->add_result(404, "Short name not found", {item_id=>$s});
} elsif (!unlink($path)) {
$envres->add_result(500, "Can't unlink: $!", {item_id=>$s});
} else {
$envres->add_result(200, "OK", {item_id=>$s});
}
}
$envres->as_struct;
}
( run in 1.791 second using v1.01-cache-2.11-cpan-39bf76dae61 )