How to copy files with Makefile.PL and ExtUtils::MakeMaker? - perl

I am developing a library and scripts in perl. For distribution I am using ExtUtils::MakeMaker, I have some configuration and data files in a directory called data in the distribution path, for example the config file is data/config.ini and data files like: data/inv01.stb. A part of the Makefile.PL code follows:
use ExtUtils::MakeMaker;
my $inifile = 'data/config.ini';
my #data = <data/*.stb>;
WriteMakefile(
NAME => 'Mymodule',
VERSION_FROM => 'lib/Mymodule.pm',
PREREQ_PM => {
'Time::HiRes' => 0,
'Storable' => 0,
'File::Path', => 0,
'File::Copy', => 0,
'Digest::CRC', => 0,
'Digest::MD5', => 0,
'Archive::Tar', => 0,
},
EXE_FILES => [ qw(scripts/check_requests.pl scripts/proc_requests.pl scripts/send_requests.pl) ],
'clean' => {FILES => clean_files()},
);
# Delete *~ files
sub clean_files {
return join(" ", "*.out", "*~", "data/test/*");
}
How can I configure the Makefile.PL to copy those files in non standard directory.
thanks for your help

Why not use EXE_FILES? After all, they are not going to be checked for runability.

Related

setting the appdir in Dancer::Test

I have an dancer webapp that I'm trying to test, and I have a few issues related to paths. It appears that the appdir setting isn't being set correctly.
The top of my test code is:
use MyApp;
use Dancer::Test;
if I dump out the settings (using dd from Data::Dump) from:
my $settings = Dancer::Config::settings();
dd $settings;
I get:
{ appdir => "/Library/WebServer/Documents/myapp/lib",
apphandler => "Standalone",
auto_reload => 0,
charset => "",
confdir => "/Library/WebServer/Documents/myapp/lib",
content_type => "text/html",
daemon => 0,
engines => {},
envdir => "/Library/WebServer/Documents/myapp/lib/environments",
environment => "development",
handlers => {},
logger => "file",
plugins => {},
port => 3000,
public => "/Library/WebServer/Documents/myapp/lib/public",
server => "0.0.0.0",
server_tokens => 1,
startup_info => 1,
template => "simple",
traces => 0,
views => "/Library/WebServer/Documents/myapp/lib/views",
warnings => 0}
clearly it's not setting the appdir correctly. It doesn't appear that it matters how I call code (i.e. the working directory).
I've been calling it as perl -I lib -I ../lib t/001_base.t with the additional library calls as MyApp.pm needs modules in both lib and ../lib.
When I run the same code as a standalone webapp which is the following in bin/app.pl which has the code:
use Dancer;
use MyApp;
dance;
dumping the settings gives me the right appdir, which loads the configuration file and sets all of the other correctly.
In my test code, I thought that adding the lines:
Dancer::set appdir=>"/Library/WebServer/Documents/myapp"
Dancer::Config->load;
would do it. However that sets the appdir correctly, but doesn't change any other parameters. From the Dancer::Test code, there is an import command which appears to do what I want, but didn't help at all. Any other thoughts?

How can I have dependencies installed automatically when using Module::Build::Mojolicious?

I'm trying to package up a Mojolicious App I wrote and have been following the instructions with Mojolicious::Plugin::InstallablePaths.
My Build.PL looks something like this;
use Module::Build::Mojolicious clean_install => 1;
my $builder = Module::Build::Mojolicious->new(
module_name => 'test',
dist_author => 'me,
license => 'perl',
configure_requires => {
'Module::Build::Mojolicious' => 0,
'Module::Build' => 0.38,
},
requires => {
'File::Find::Rule' => 0,
'File::MMagic' => 0,
'Mojolicious' => 0,
'Mojolicious::Plugin::Authorization' => 0,
'Crypt::Blowfish' => 0,
'Experimental' => 0,
},
share_dir => 'lib/Jacaranda/files',
);
$builder->create_build_script;
My question is how do I get the dependencies to run the script, namely Module::Build::Mojolicious installed without having to install them from CPAN manually?
I don't want people who want to install my application to have to install these dependencies manually.
Like any Perl module, you should just be able to tell the cpan client to install the dependencies. I recommend using cpanm, using it is as simple as
$ cpanm --instaldeps .

Set different directories to upload files in TYPO3 from a single field

I have a field in TCA with type group->file and I need to save the files in different directories depending on the year.
Usually when I need to pos-process any field I use the processDatamap_afterDatabaseOperations hook but it is not working properly with files.
This is what I'm doing.
function processDatamap_afterDatabaseOperations ($status, $table, $id, &$fieldArray, &$reference) {
if ($table=='tx_students' && isset($fieldArray['documents'])){
$path = $_SERVER['DOCUMENT_ROOT'].'/folder/';
$folder = date('Y').'/';
$filename = date('Y-m-d').' '.$student['first_name'].' '.$student['last_name'].'.zip';
$filename = str_replace(' ','_',$filename);
if (!file_exists($path.$folder)) {
mkdir($path.$folder, 0755, true);
$fh = fopen($path.$folder.'index.html','w+');
fclose($fh);
}
rename($path.$fieldArray['documents'],$path.$folder.$filename);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.$student['uid'],array('documents'=>$folder.$filename));
}
}
I'm trying to store the filename in the DB with the folder path and that works well the first time I save the form. But the following times I get an error because TYPO3 can't find the file. It happens when I try to delete the file as well clicking in the x.
This is the TCA for that field:
'documents' => array(
'exclude' => 1,
'label' => '',
'config' => array(
'type' => 'group',
'internal_type' => 'file',
'allowed' => 'zip',
'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
'uploadfolder' => 'uploads/incoming',
'show_thumbs' => 1,
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
I want to have those files organized by year but I don't know how to do this in TYPO3. Is it another hook for doing this? It seems like TYPO3 was removing the part of the path before the slash for certain operations.
I'm working with TYPO3 4.5 LTS. Any suggestions?
upgrade to 6.2 beta
use fal
use the categories to sort / categorize your files.
The directories you are using are not intended to be used this way ;)

What is the Module::Build equivalent to ExtUils::MakeMaker INST_SCRIPT?

I want to convert a project from use of ExtUtils::MakeMaker to Module::Build.
As the Makefile.PL is mostly default and Module::Build::Convert did not work for me (see below) I want to convert it manually but did not find the equivalent of INST_SCRIPT to place the executables in Perl's bin/ directory.
My WriteMakefile looks like this.
WriteMakefile(
NAME => 'Project',
AUTHOR => q{Mugen Kenichi <mugen.kenichi#uninets.eu>},
VERSION_FROM => 'lib/Project.pm',
INST_SCRIPT => 'script/',
($ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
: ()),
PL_FILES => {},
PREREQ_PM => {
'JSON' => 0,
'Log::Log4perl' => 0,
'Proc::Daemon' => 0,
'Term::ANSIColor' => 0,
'MooseX::Declare' => 0.34,
'MooseX::Log::Log4perl' => 0,
'Moose::Util::TypeConstraints' => 0,
'MooseX::Templated::Role' => 0,
'Template' => 0,
# for testing
'Test::More' => 0,
'MooseX::Params::Validate' => 0,
'File::Temp' => 0,
'Sub::Exporter::ForMethods' => 0,
'Data::Section' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Project-*' },
);
I tried to use Module::Build::Convert but make2build throws errors i could not resolve:
Variable "$regex" will not stay shared at (re_eval 32) line 1.
Use of uninitialized value $lines[0] in pattern match (m//) at /home/mak/perl5/lib/perl5/Module/Build/Convert.pm line 1305, <DATA> line 1.
perl version:
perl -v
This is perl 5, version 12, subversion 3 (v5.12.3) built for x86_64-linux
If that's what your Makefile.PL looks like, leave it like that. Don't switch to Module::Build, which appears to be an abandoneed build system. No one maintains Module::Build anymore, and until Leon Timmermans comes out with the next thing, unless there's some feature in Module::Build you absolutely must have, there's no reason to convert to it.
Having said that though, I create the list of script files and use it as the value for script_files. It's not as nice. See my Build.PL for Unicode::Tussle.

A method for changing INCLUDE_PATH in Template::Toolkit on the FLY

If I have a preloaded Template::Toolkit object, in mod_perl enviroment for example, is there any way to change INCLUDE_PATH array without recreating the object?
I use the Template::Provider for this
my $template_config = {
INCLUDE_PATH => "/path/to/templates",
ENCODING => 'utf8',
};
# Create template_provider manually so that we can manipulate template path
# later.
my $template_provider = Template::Provider->new($template_config);
my $tt = Template->new({
LOAD_TEMPLATES => [$template_provider ],
PRE_CHOMP => 2,
POST_CHOMP => 3,
TRIM => 1,
ENCODING => 'utf8',
}) || die $Template::ERROR;
# somewhere else later
$template_provider->include_path([
"$dir/templates/$language",
"$dir/templates"]);