| 1 |
NAME |
| 2 |
Module::Bundled::Files - Access files bundled with Module |
| 3 |
|
| 4 |
VERSION |
| 5 |
Version 0.03 |
| 6 |
|
| 7 |
SYNOPSIS |
| 8 |
Access files installed with your module without needing to specify an |
| 9 |
install location on the target filesystem. |
| 10 |
|
| 11 |
Setup |
| 12 |
In *Build.PL*: |
| 13 |
|
| 14 |
my $build = new Module::Build(...); |
| 15 |
map{$build->add_build_element($_);} |
| 16 |
qw{txt html tmpl}; |
| 17 |
# installs all .txt, .html and .tmpl files found in the lib/ tree |
| 18 |
|
| 19 |
Create files: |
| 20 |
|
| 21 |
Build.PL |
| 22 |
lib/ |
| 23 |
My/ |
| 24 |
Module.pm |
| 25 |
Module/ |
| 26 |
index.html |
| 27 |
data.txt |
| 28 |
form.tmpl |
| 29 |
|
| 30 |
Object-Oriented Interface |
| 31 |
use base qw{Module::Bundled::Files}; |
| 32 |
|
| 33 |
if($self->mbf_exists('data.txt')){...} |
| 34 |
|
| 35 |
my $filename = $self->mbf_path('data.txt'); |
| 36 |
# $filename = '/usr/local/share/perl/5.8.7/My/Module/data.txt'; |
| 37 |
open my $fh, '<', $filename or die $@; |
| 38 |
|
| 39 |
my $fh = $self->mbf_open('data.txt'); |
| 40 |
while(<$fh>) |
| 41 |
{ |
| 42 |
... |
| 43 |
} |
| 44 |
|
| 45 |
my $data = $self->mbf_read('data.txt'); |
| 46 |
|
| 47 |
Non-Object-Oriented Interface |
| 48 |
use Module::Bundled::Files qw{:all}; |
| 49 |
my $object = new Other::Object; |
| 50 |
|
| 51 |
if(mf_exists($other,'otherfile.txt')){...} |
| 52 |
|
| 53 |
my $filename = mbf_path($object,'otherfile.txt'); |
| 54 |
|
| 55 |
open my $fh, '<', $filename or die $@; |
| 56 |
|
| 57 |
my $fh = mbf_open($object,'otherfile.txt'); |
| 58 |
while(<$fh>) |
| 59 |
{ |
| 60 |
... |
| 61 |
} |
| 62 |
|
| 63 |
my $data = mbf_read($object,'otherfile.txt'); |
| 64 |
|
| 65 |
DESCRIPTION |
| 66 |
This module provides an simple method of accessing files that need to be |
| 67 |
bundled with a module. |
| 68 |
|
| 69 |
For example, a module My::Module, which needs to access a seperate file |
| 70 |
*data.txt*. |
| 71 |
|
| 72 |
In your development directory you would place your *data.txt* in your |
| 73 |
*lib/My/Module/* directory. |
| 74 |
|
| 75 |
lib/ |
| 76 |
My/ |
| 77 |
Module.pm |
| 78 |
Module/ |
| 79 |
data.txt |
| 80 |
|
| 81 |
Using *add_build_element(...)* in your *Build.PL* file allows the |
| 82 |
*data.txt* file to be installed in the same relative location. |
| 83 |
|
| 84 |
The file(s) can then be accessed using the *mbf_** functions provided by |
| 85 |
this module. |
| 86 |
|
| 87 |
EXPORT |
| 88 |
The following functions can be exported if you will not be using the |
| 89 |
Object-Oriented Interface. |
| 90 |
|
| 91 |
:all |
| 92 |
mbf_validate |
| 93 |
mbf_dir |
| 94 |
mbf_exists |
| 95 |
mbf_path |
| 96 |
mbf_open |
| 97 |
mbf_read |
| 98 |
|
| 99 |
FUNCTIONS |
| 100 |
mbf_validate(FILENAME) |
| 101 |
Returns true if the filename does not contain illegal sequences (i.e. |
| 102 |
'..') |
| 103 |
|
| 104 |
Dies if filename is invalid. |
| 105 |
|
| 106 |
mbf_dir([MODULE]) |
| 107 |
Returns the path of the directory where all files would be installed. |
| 108 |
|
| 109 |
The non-OO interface requires an object reference or module name as the |
| 110 |
only parameter. |
| 111 |
|
| 112 |
mbf_exists([MODULE,] FILENAME) |
| 113 |
Returns true of the named file has been bundled with the module. |
| 114 |
|
| 115 |
The non-OO interface requires an object reference or module name as the |
| 116 |
first parameter. |
| 117 |
|
| 118 |
mbf_path([MODULE,] FILENAME) |
| 119 |
Returns the full path to the named file. Dies if the file does not |
| 120 |
exist. |
| 121 |
|
| 122 |
Will look for file in inherited classes (by reading @ISA) if the file is |
| 123 |
not found for the derived class. @ISA navigation is the same as per Perl |
| 124 |
searching for methods. See Class::ISA for more details. |
| 125 |
|
| 126 |
The non-OO interface requires an object reference or module name as the |
| 127 |
first parameter. |
| 128 |
|
| 129 |
mbf_open([MODULE,] FILENAME) |
| 130 |
Returns an open file handle for the named file. Dies if the file does |
| 131 |
not exist. |
| 132 |
|
| 133 |
The non-OO interface requires an object reference or module name as the |
| 134 |
first parameter. |
| 135 |
|
| 136 |
mbf_read([MODULE,] FILENAME) |
| 137 |
Returns the content of the named file. Dies if the file does not exist. |
| 138 |
|
| 139 |
The non-OO interface requires an object reference or module name as the |
| 140 |
first parameter. |
| 141 |
|
| 142 |
AUTHOR |
| 143 |
Paul Campbell, "<[email protected]>" |
| 144 |
|
| 145 |
BUGS |
| 146 |
Please report any bugs or feature requests to |
| 147 |
"[email protected]", or through the web interface at |
| 148 |
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Module-Bundled-Files>. I |
| 149 |
will be notified, and then you will automatically be notified of |
| 150 |
progress on your bug as I make changes. |
| 151 |
|
| 152 |
#=head1 ACKNOWLEDGEMENTS |
| 153 |
|
| 154 |
COPYRIGHT & LICENSE |
| 155 |
Copyright 2005 Paul Campbell, all rights reserved. |
| 156 |
|
| 157 |
This program is free software; you can redistribute it and/or modify it |
| 158 |
under the same terms as Perl itself. |
| 159 |
|