Aion-Fs
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Aion/Fs.pm view on Meta::CPAN
package Aion::Fs;
use 5.22.0;
no strict; no warnings; no diagnostics;
use common::sense;
our $VERSION = "0.0.6";
use Exporter qw/import/;
use Scalar::Util qw//;
use Time::HiRes qw//;
our @EXPORT = our @EXPORT_OK = grep {
ref \$Aion::Fs::{$_} eq "GLOB" && *{$Aion::Fs::{$_}}{CODE} && !/^(?:_|(NaN|import)\z)/
} keys %Aion::Fs::;
# Ðз пакеÑа в ÑайловÑй пÑÑÑ
sub from_pkg(;$) {
my ($pkg) = @_ == 0? $_: @_;
$pkg =~ s!::!/!g;
"$pkg.pm"
}
# Ðз Ñайлового пÑÑи в пакеÑ
sub to_pkg(;$) {
my ($path) = @_ == 0? $_: @_;
$path =~ s!\.\w+$!!;
$path =~ s!/!::!g;
$path
}
# ÐодклÑÑÐ°ÐµÑ Ð¼Ð¾Ð´ÑлÑ, еÑли он еÑÑ Ð½Ðµ подклÑÑÑн, и возвÑаÑÐ°ÐµÑ ÐµÐ³Ð¾
sub include(;$) {
my ($pkg) = @_;
$pkg = $_ if @_ == 0;
return $pkg if $pkg->can("new");
my $path = from_pkg $pkg;
return $pkg if exists $INC{$path};
require $path;
$pkg
}
# как mkdir -p
use constant FILE_EXISTS => 17;
use constant DIR_DEFAULT_PERMISSION => 0755;
sub mkpath (;$) {
my ($path) = @_;
$path = $_ if @_ == 0;
my $permission;
($path, $permission) = @$path if ref $path;
$permission = DIR_DEFAULT_PERMISSION unless Scalar::Util::looks_like_number $permission;
while($path =~ m!/!g) {
mkdir $`, $permission
or ($! != FILE_EXISTS? die "mkpath $`: $!": ())
if $` ne '';
}
undef $!;
$path
}
# СÑиÑÑÐ²Ð°ÐµÑ Ñайл
sub cat(;$) {
my ($file) = @_;
$file = $_ if @_ == 0;
my $layer = ":utf8";
($file, $layer) = @$file if ref $file;
open my $f, "<$layer", $file or die "cat $file: $!";
read $f, my $x, -s $f;
close $f;
$x
}
# запиÑаÑÑ Ñайл
view all matches for this distributionview release on metacpan - search on metacpan
( run in 5.893 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )