NAME
Path::Resource - URI/Path::Class combination.
VERSION
Version 0.01_2
SYNOPSIS
use Path::Resource;
# Map a resource on the local disk to a URI.
# Its (disk) directory is "/var/dir" and its uri is "http://hostname/loc"
my $rsc = new Path::Resource dir => "/var/dir", uri => [ "http://hostname", "loc" ];
# uri: http://hostname/loc
# dir: /var/dir
my $subrsc = $rsc->subdir("subdir");
# uri: http://hostname/loc/subdir
# dir: /var/dir/subdir
my $filersc = $rsc->subfile("info.txt");
# uri: http://hostname/loc/subdir/info.txt
# file: /var/dir/subdir/info.txt
my $filesize = -s $filersc->file;
redirect($filersc->uri);
METHODS
- $rsc = Path::Resource->new( ... );
- $rsc = Path::Resource->new( uri => <uri> dir => <dir>, ... );
-
Returns a new
Path::Resource
object. A resource can either be a file resource or a directory resource.The constructor accepts the following:
uri =>
URI
. The base uri of the resource. This can be or will become aURI
object. This can also be a uri-like string, e.g. "http://example.com/..."uri => [
URI
, <loc> ]. The base uri of the resource. This option will seturi
andloc
at the same time. For example, if you passuri =
[ "http://example.com", "/loc" ]>, then the final uri will behttp://example.com/loc
and the final loc will be/loc
.dir => The base dir of the resource. This can be or will become a
Path::Class::Dir
object.file => The file of the resource. This can be or will become a
Path::Class::File
object.path => The starting path of the resource, relative to dir and uri. Adding path to the base uri/base dir will yield the actual uri/dir.
Note: Passing the file object will mark the resource as being a file resource object (You can't subdir or subfile a file resource.
- $rsc->is_file
-
Returns true if the $rsc maps to a file, false otherwise.
- $rsc->is_dir
-
Returns true if the $rsc maps to a directory, false otherwise.
- $clonersc = $rsc->clone
- $clonersc = $rsc->clone(path => <path>, ...);
-
Returns a new
Path::Resource
object that is a clone of $rsc; optionally changing any path file, dir, loc, or uri components. - $subrsc = $rsc->subdir( <dir1>, <dir2>, ... )
-
Returns a new
Path::Resource
object representing a subdirectory resource of $rsc. - $subfile = $rsc->subfile( <dir1>, <dir2>, ..., <file> )
- $parentrsc = $rsc->parent
- $dir = $rsc->dir
- $file = $rsc->file
- $loc = $rsc->loc
- $uri = $rsc->uri
AUTHOR
Robert Krimen, <rkrimen at cpan.org>
BUGS
Please report any bugs or feature requests to bug-path-resource at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Path-Resource. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Path::Resource
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
RT: CPAN's request tracker
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2007 Robert Krimen, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.