Perl

From Leaky
Revision as of 09:41, 16 August 2016 by Leaky (talk | contribs) (Custom Perl: some frequently used modules)
Jump to: navigation, search

Frameworks

Modules

DBIx::Class modules

Custom Perl

Installing a custom version of Perl just for a single user (e.g a project) without breaking the system-wide Perl.

Packages required:

gcc patch bzip2 gcc-c++ make automake

As the unprivileged user:

$ curl -L https://install.perlbrew.pl | bash
$ source ~/perl5/perlbrew/etc/bashrc
$ perlbrew install perl-5.20.1
$ perlbrew switch perl-5.20.1
$ perlbrew install-cpanm
$ echo 'source /home/plates/perl5/perlbrew/etc/bashrc' >> ~/.bashrc

After this you should be always using Perl 5.20.1 as this user (that's what the perlbrew switch does). To install modules, simply use cpanm followed by the module name.

Extra Perl modules for Catalyst dev

After installing a custom version of Perl as above it's a good idea to install a bunch of frequently used modules if you're doing any kind of Catalyst development.

cpanm Catalyst::Devel DBIx::Class::TimeStamp DBIx::Class::PassphraseColumn \
  DBIx::Class::InflateColumn::Serializer Catalyst::Model::DBIC::Schema \
  Catalyst::Plugin::Authentication Catalyst::Plugin::Authorization::Roles \
  Catalyst::Plugin::Session Catalyst::Plugin::Session::Store::DBI \
  Catalyst::Plugin::Session::State::Cookie Catalyst::Plugin::StatusMessage \
  Catalyst::Authentication::Store::DBIx::Class Catalyst::View::TT \
  Catalyst::View::JSON Log::Log4perl::Catalyst DBD::mysql Email::Valid \
  Text::CSV_XS LWP::Protocol::https XML::Simple XML::Writer GD::Image \
  GD::Text FCGI::ProcManager Catalyst::View::Email::Template \
  Template::Plugin::DateTime HTML::Tiny Hashids Term::Size::Any Time::ParseDate

Tips

Mixing STDOUT and STDERR output in the right order

STDOUT and STDERR are block buffered when there is no terminal, or line buffered when there is a terminal. This has the unfortunate side effect of making output from print/warn mess up when running a script from cron when the same script works perfectly run from the command line.

Redirect STDERR to the same stream as STDOUT (equiv to 2>&1 in bash) - this isn't essential, but makes it easier to pipe the output through tail/mail/etc, or redirect the output to a logfile.

close(STDERR);
open(STDERR, ">&STDOUT");

Make both streams non-buffering

select(STDERR);
$| = 1;
select(STDOUT);
$| = 1;

Alternatively, instead of the select() above, you can use IO::Handle

use IO::Handle;
STDERR->autoflush(1);
STDOUT->autoflush(1);