Tag: perl
Create command-line applications with both human and computer friendly output in Perl
https://perlancar.wordpress.com/2015/03/13/pericmd-039-creating-api-friendly-cli-applications-with-parseable-outputs/ ᔥ
Outputs in various tabular formats…
% ./list-files -v
+----------------+------+------+
| name | size | type |
+----------------+------+------+
| hello | 1131 | f |
| list-files | 988 | f |
| list-files~ | 989 | f |
| mycomp | 902 | f |
| mycomp2a | 608 | f |
| mycomp2b | 686 | f |
| mycomp2b+comp | 1394 | f |
| pause | 4096 | d |
| perl-App-hello | 4096 | d |
+----------------+------+------+
…Or JSON format:
% ./list-files --json
[200,"OK",["hello","list-files","list-files~","mycomp","mycomp2a","mycomp2b","mycomp2b+comp","pause","perl-App-hello"],{}]
Moose: Perl module that extends the Perl 5 object system to make programming easier, more consistent, and less tedious
http://search.cpan.org/~ether/Moose-2.1402/lib/Moose.pm ᔥ
- Moose Manual: http://search.cpan.org/~ether/Moose-2.1402/lib/Moose/Manual.pod
- Moose Cookbook: http://search.cpan.org/~ether/Moose-2.1402/lib/Moose/Cookbook.pod
- Moose Home Page: http://moose.iinteractive.com/en/
- Podcast where the Moose “Roles” system is discussed in some detail: http://thechangelog.com/133/
This module has me interested in writing some Perl code for the first time in years. I’m going to check this out.
Example from perldocs:
package Person;
use Moose;
has 'first_name' => (
is => 'rw',
isa => 'Str',
);
has 'last_name' => (
is => 'rw',
isa => 'Str',
);
no Moose;
__PACKAGE__->meta->make_immutable;
This is a complete and usable class definition!
package User;
use DateTime;
use Moose;
extends 'Person';
has 'password' => (
is => 'rw',
isa => 'Str',
);
has 'last_login' => (
is => 'rw',
isa => 'DateTime',
handles => { 'date_of_last_login' => 'date' },
);
sub login {
my $self = shift;
my $pw = shift;
return 0 if $pw ne $self->password;
$self->last_login( DateTime->now() );
return 1;
}
no Moose;
__PACKAGE__->meta->make_immutable;
When ready to instantiate your class in an application, use it in the “traditional” Perl manner:
use User;
my $user = User->new(
first_name => 'Example',
last_name => 'User',
password => 'letmein',
);
$user->login('letmein');
say $user->date_of_last_login;
Link: All Things Perl With Curtis “Ovid” Poe (Podcast Interview)
Link: git-feed: Generate Atom feeds for git commit logs
https://github.com/brennen/git-feed ᔥ
Requires Perl module XML::Atom::SimpleFeed
.
Perl Dancer: Perl Web Application Framework
- Dead Simple – Intuitive, minimalist and very expressive syntax.
- Flexible – PSGI support, plugins and modular design allow for strong scalability.
- Few dependencies – Dancer depends on as few CPAN modules as possible making it easy to install.
Rex: Agentless, plain Perl deployment & configuration management framework that works over SSH
Mojolicious: Modern Perl web framework
I haven’t written any Perl in years, but this looks promising.
- An amazing real-time web framework, allowing you to easily grow single file Mojolicious::Lite prototypes into well structured web applications.
- Powerful out of the box with RESTful routes, plugins, commands, Perl-ish templates, content negotiation, session management, form validation, testing framework, static file server, first class Unicode support and much more for you to discover.
- Very clean, portable and Object Oriented pure-Perl API without any hidden magic and no requirements besides Perl 5.10.1 (although 5.18+ is recommended, and optional CPAN modules will be used to provide advanced functionality if they are installed).
- Full stack HTTP and WebSocket client/server implementation with IPv6, TLS, SNI, IDNA, Comet (long polling), keep-alive, connection pooling, timeout, cookie, multipart, proxy and gzip compression support.
- Built-in non-blocking I/O web server, supporting multiple event loops as well as optional preforking and hot deployment, perfect for embedding.
- Automatic CGI and PSGI detection.
- JSON and HTML/XML parser with CSS selector support.
- Fresh code based upon years of experience developing Catalyst.