Aion-Fs
view release on metacpan or search on metacpan
lib/Aion/Fs.pm view on Meta::CPAN
};
path '.$.Directory.Directory.' # --> $path
path {volume => "ADFS::HardDisk.", file => "File"} # => ADFS::HardDisk.$.File
path {folder => "x"} # => x.
path {dir => "x."} # => x.
}
{
local $^O = "MacOS";
my $path = {
path => '::::mix:report.doc',
dir => "::::mix:",
folder => ":::mix",
file => "report.doc",
name => "report",
ext => "doc",
};
path $path->{path} # --> $path
path $path # => $path->{path}
path 'report' # --> {path => 'report', file => 'report', name => 'report'}
path {volume => "x", file => "f"} # => x:f
path {folder => "x"} # => x:
}
{
local $^O = "vmesa";
my $path = {
path => ' USERID FILE EXT VOLUME ',
userid => "USERID",
file => "FILE EXT",
name => "FILE",
ext => "EXT",
volume => "VOLUME",
};
path $path->{path} # --> $path
path {volume => "x", file => "f"} # -> ' f x'
}
=head3 See also
=over
=item * https://en.wikipedia.org/wiki/Path_(computing)
=back
Modules for determining the OS, and therefore determining what file paths are in the OS:
=over
=item * C<$^O> â superglobal variable with the name of the current OS.
=item * L<Devel::CheckOS>, L<Perl::OSType> â define the OS.
=item * L<Devel::AssertOS> â prohibits the use of the module outside the specified OS.
=item * L<System::Info> â information about the OS, its version, distribution, CPU and host.
=back
Parts of file paths are distinguished:
=over
=item * L<File::Spec> â C<< ($volume, $directories, $file) = File::Spec-E<gt>splitpath($path) >>. Only supports unix, win32, os/2, vms, cygwin and amigaos.
=item * L<File::Spec::Functions> - C<($volume, $directories, $file) = splitpath($path)>.
=item * L<File::Spec::Mac> - included in L<File::Spec>, but not defined by it, so it has to be used separately. For mac os version 9.
=item * L<File::Basename> â C<($name, $path, $suffix) = fileparse($fullname, @suffixlist)>.
=item * L<Path::Class::File> â C<< file('foo', 'bar.txt')-E<gt>is_absolute >>.
=item * L<Path::Extended::File> â C<< Path::Extended::File-E<gt>new($file)-E<gt>basename >>.
=item * L<Mojo::File> â C<< path($file)-E<gt>extname >>.
=item * L<Path::Util> - C<$filename = basename($dir)>.
=item * L<Parse::Path> â C<< Parse::Path-E<gt>new(path =E<gt> 'gophers[0].food.count', style =E<gt> 'DZIL')-E<gt>push("chunk") >>. Works with paths as arrays (C<push>, C<pop>, C<shift>, C<splice>). It also overloads comparison operators. It has sty...
=back
=head2 transpath ($path?, $from, $to)
Converts a path from one OS format to another.
If C<$path> is not specified, C<$_> is used.
For a list of supported operating systems, see the examples of the C<path> subroutine just above or like this: C<keys %Aion::Fs::FS>.
OS names are case insensitive.
local $_ = ">x>y>z.doc.zip";
transpath "vos", "unix" # \> /x/y/z.doc.zip
transpath "vos", "VMS" # \> [.x.y]z.doc.zip
transpath $_, "vos", "RiscOS" # \> .x.y.z/doc/zip
=head2 splitdir (;$dir)
Splits a directory into components. The directory should first be obtained from C<< path-E<gt>{dir} >>.
local $^O = "unix";
[ splitdir "/x/" ] # --> ["", "x", ""]
=head2 joindir (;$dirparts)
Combines a directory from its components. The resulting directory should then be included in C<< path +{dir =E<gt> $dir} >>.
local $^O = "unix";
lib/Aion/Fs.pm view on Meta::CPAN
include("A")->new # ~> A=HASH\(0x\w+\)
[map include, qw/A N/] # --> [qw/A N/]
{ local $_="N"; include->ex } # -> 123
=head2 catonce (;$file)
Reads the file for the first time. Any subsequent attempt to read this file returns C<undef>. Used to insert js and css modules into the resulting file. Without a parameter, uses C<$_>.
=over
=item * C<$file> can contain arrays of two elements. The first is considered as a path, and the second as a layer. The default layer is C<:utf8>.
=item * If C<$file> is not specified, use C<$_>.
=back
local $_ = "catonce.txt";
lay "result";
catonce # -> "result"
catonce # -> undef
eval { catonce[] }; $@ # ~> catonce not use ref path!
=head2 wildcard (;$wildcard)
Converts a file mask to a regular expression. Without a parameter, uses C<$_>.
=over
=item * C<**> - C<[^/]*>
=item * C<*> - C<.*>
=item * C<?> - C<.>
=item * C<??> - C<[^/]>
=item * C<{> - C<(>
=item * C<}> - C<)>
=item * C<,> - C<|>
=item * Other characters are escaped using C<quotemeta>.
=back
wildcard "*.{pm,pl}" # \> (?^usn:^.*?\.(pm|pl)$)
wildcard "?_??_**" # \> (?^usn:^._[^/]_[^/]*?$)
Used in filters of the C<find> function.
=head3 See also
=over
=item * L<File::Wildcard>.
=item * L<String::Wildcard::Bash>.
=item * L<Text::Glob> â C<glob_to_regex("*.{pm,pl}")>.
=back
=head2 goto_editor ($path, $line)
Opens the file in the editor from .config at the specified line. Defaults to C<vscodium %p:%l>.
.config.pm file:
package config;
config_module 'Aion::Fs' => {
EDITOR => 'echo %p:%l > ed.txt',
};
1;
goto_editor "mypath", 10;
cat "ed.txt" # => mypath:10\n
eval { goto_editor "`", 1 }; $@ # ~> `:1 --> 512
=head2 from_pkg (;$pkg)
Transfers the packet to the FS path. Without a parameter, uses C<$_>.
from_pkg "Aion::Fs" # => Aion/Fs.pm
[map from_pkg, "Aion::Fs", "A::B::C"] # --> ["Aion/Fs.pm", "A/B/C.pm"]
=head2 to_pkg (;$path)
Translates the path from the FS to the package. Without a parameter, uses C<$_>.
to_pkg "Aion/Fs.pm" # => Aion::Fs
[map to_pkg, "Aion/Fs.md", "A/B/C.md"] # --> ["Aion::Fs", "A::B::C"]
=head2 from_inc (;$pkg)
Translates the packet to the FS path in C<@INC>. The package file must exist in one of the C<@INC> paths. Without a parameter, uses C<$_>.
from_inc "Aion::Fs" # -> $INC{'Aion/Fs.pm'}
[map from_inc, "A::B::C", "Aion::Fs"] # --> [$INC{'Aion/Fs.pm'}]
from_inc "A::B::C" # -> undef
=head2 to_inc (;$path)
Translates the path from FS to C<@INC> into a package. Without a parameter, uses C<$_>.
to_inc $INC{'Aion/Fs.pm'} # => Aion::Fs
[map to_inc,"A/B/C.pm", $INC{'Aion/Fs.pm'}] # --> ["Aion::Fs"]
to_inc 'Aion/Fs.pm' # -> undef
=head2 ilay (;$path)
Creates a file descriptor. It knows how to close as soon as the last link to it disappears.
( run in 0.685 second using v1.01-cache-2.11-cpan-5735350b133 )