2011-06-20 13:40:28 -04:00
|
|
|
# #!/usr/bin/perl
|
|
|
|
snippet #!
|
2012-03-19 15:04:44 -04:00
|
|
|
#!/usr/bin/env perl
|
2011-06-20 13:40:28 -04:00
|
|
|
|
|
|
|
# Hash Pointer
|
|
|
|
snippet .
|
|
|
|
=>
|
|
|
|
# Function
|
|
|
|
snippet sub
|
|
|
|
sub ${1:function_name} {
|
|
|
|
${2:#body ...}
|
|
|
|
}
|
|
|
|
# Conditional
|
|
|
|
snippet if
|
|
|
|
if (${1}) {
|
|
|
|
${2:# body...}
|
|
|
|
}
|
|
|
|
# Conditional if..else
|
|
|
|
snippet ife
|
|
|
|
if (${1}) {
|
|
|
|
${2:# body...}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
${3:# else...}
|
|
|
|
}
|
|
|
|
# Conditional if..elsif..else
|
|
|
|
snippet ifee
|
|
|
|
if (${1}) {
|
|
|
|
${2:# body...}
|
|
|
|
}
|
|
|
|
elsif (${3}) {
|
|
|
|
${4:# elsif...}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
${5:# else...}
|
|
|
|
}
|
|
|
|
# Conditional One-line
|
|
|
|
snippet xif
|
|
|
|
${1:expression} if ${2:condition};${3}
|
|
|
|
# Unless conditional
|
|
|
|
snippet unless
|
|
|
|
unless (${1}) {
|
|
|
|
${2:# body...}
|
|
|
|
}
|
|
|
|
# Unless conditional One-line
|
|
|
|
snippet xunless
|
|
|
|
${1:expression} unless ${2:condition};${3}
|
|
|
|
# Try/Except
|
|
|
|
snippet eval
|
2011-11-26 20:46:51 -05:00
|
|
|
local $@;
|
2011-06-20 13:40:28 -04:00
|
|
|
eval {
|
|
|
|
${1:# do something risky...}
|
|
|
|
};
|
2011-11-26 20:46:51 -05:00
|
|
|
if (my $e = $@) {
|
2011-06-20 13:40:28 -04:00
|
|
|
${2:# handle failure...}
|
|
|
|
}
|
|
|
|
# While Loop
|
|
|
|
snippet wh
|
|
|
|
while (${1}) {
|
|
|
|
${2:# body...}
|
|
|
|
}
|
|
|
|
# While Loop One-line
|
|
|
|
snippet xwh
|
|
|
|
${1:expression} while ${2:condition};${3}
|
|
|
|
# C-style For Loop
|
|
|
|
snippet cfor
|
|
|
|
for (my $${2:var} = 0; $$2 < ${1:count}; $$2${3:++}) {
|
|
|
|
${4:# body...}
|
|
|
|
}
|
|
|
|
# For loop one-line
|
|
|
|
snippet xfor
|
|
|
|
${1:expression} for @${2:array};${3}
|
|
|
|
# Foreach Loop
|
|
|
|
snippet for
|
|
|
|
foreach my $${1:x} (@${2:array}) {
|
|
|
|
${3:# body...}
|
|
|
|
}
|
|
|
|
# Foreach Loop One-line
|
|
|
|
snippet fore
|
|
|
|
${1:expression} foreach @${2:array};${3}
|
|
|
|
# Package
|
|
|
|
snippet cl
|
|
|
|
package ${1:ClassName};
|
|
|
|
|
2012-05-16 02:21:55 -04:00
|
|
|
#use parent qw(${2:ParentClass});
|
2012-05-16 04:32:53 -04:00
|
|
|
|
|
|
|
${3:#...}
|
2011-06-20 13:40:28 -04:00
|
|
|
|
2012-05-16 04:32:53 -04:00
|
|
|
1;
|
2012-05-16 02:21:55 -04:00
|
|
|
|
|
|
|
__END__
|
|
|
|
|
2012-05-16 04:32:53 -04:00
|
|
|
# Moose package
|
|
|
|
snippet moosecl
|
|
|
|
package ${1:ClassName};
|
2012-05-16 02:21:55 -04:00
|
|
|
|
2012-05-16 04:32:53 -04:00
|
|
|
use Moose;
|
|
|
|
#extends '${2:# ParentClass}';
|
|
|
|
|
|
|
|
${3:#...}
|
2012-05-16 02:21:55 -04:00
|
|
|
|
2012-05-16 04:32:53 -04:00
|
|
|
1;
|
2012-05-16 02:21:55 -04:00
|
|
|
|
|
|
|
|
2012-05-16 04:32:53 -04:00
|
|
|
__END__
|
|
|
|
|
|
|
|
|
|
|
|
# Package syntax perl >= 5.12.0
|
|
|
|
snippet package
|
|
|
|
package ${1:ClassName} ${2:0.99};
|
|
|
|
|
|
|
|
${3:#...}
|
2012-05-16 02:21:55 -04:00
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
2012-05-16 04:32:53 -04:00
|
|
|
|
|
|
|
#moose
|
|
|
|
snippet moose
|
|
|
|
use Moose;
|
|
|
|
|
|
|
|
# moose extends
|
|
|
|
snippet extends
|
|
|
|
extends qw(${1:Parent Class});
|
|
|
|
|
|
|
|
# parent
|
|
|
|
snippet parent
|
|
|
|
use parent qw(${1:Parent Class});
|
|
|
|
|
2011-06-20 13:40:28 -04:00
|
|
|
# Read File
|
|
|
|
snippet slurp
|
|
|
|
my $${1:var} = do { local $/; open my $file, '<', "${2:file}"; <$file> };
|
|
|
|
${3}
|
2011-09-09 12:57:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
# strict warnings
|
|
|
|
snippet strwar
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
|
|
|
|
# standard versioning with perlcritic bypass
|
|
|
|
snippet vers
|
|
|
|
## no critic
|
|
|
|
our $VERSION = '${1:version}';
|
|
|
|
eval $VERSION;
|
|
|
|
## use critic
|
|
|
|
|
|
|
|
|
|
|
|
# new 'switch' like feature
|
|
|
|
snippet switch
|
|
|
|
use feature 'switch';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Anonymous subroutine
|
|
|
|
snippet asub
|
|
|
|
sub {
|
|
|
|
${1:# body }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Begin block
|
|
|
|
snippet begin
|
|
|
|
BEGIN {
|
|
|
|
${1:# begin body}
|
|
|
|
}
|
|
|
|
|
|
|
|
# call package function with some parameter
|
|
|
|
snippet pkgmv
|
2012-03-10 17:24:03 -05:00
|
|
|
__PACKAGE__->${1:package_method}(${2:var})
|
2011-09-09 12:57:55 -04:00
|
|
|
|
|
|
|
# call package function without a parameter
|
|
|
|
snippet pkgm
|
2012-03-10 17:24:03 -05:00
|
|
|
__PACKAGE__->${1:package_method}()
|
2011-09-09 12:57:55 -04:00
|
|
|
|
|
|
|
# call package "get_" function without a parameter
|
|
|
|
snippet pkget
|
2012-03-10 17:24:03 -05:00
|
|
|
__PACKAGE__->get_${1:package_method}()
|
2011-09-09 12:57:55 -04:00
|
|
|
|
|
|
|
# call package function with a parameter
|
|
|
|
snippet pkgetv
|
2012-03-10 17:24:03 -05:00
|
|
|
__PACKAGE__->get_${1:package_method}(${2:var})
|
2011-09-09 12:57:55 -04:00
|
|
|
|
|
|
|
# complex regex
|
|
|
|
snippet qrx
|
|
|
|
qr/
|
|
|
|
${1:regex}
|
|
|
|
/xms
|
|
|
|
|
|
|
|
#simpler regex
|
|
|
|
snippet qr/
|
|
|
|
qr/${1:regex}/x
|
|
|
|
|
|
|
|
#given
|
|
|
|
snippet given
|
|
|
|
given ($${1:var}) {
|
|
|
|
${2:# cases}
|
|
|
|
${3:# default}
|
|
|
|
}
|
|
|
|
|
|
|
|
# switch-like case
|
|
|
|
snippet when
|
|
|
|
when (${1:case}) {
|
|
|
|
${2:# body}
|
|
|
|
}
|
|
|
|
|
|
|
|
# hash slice
|
|
|
|
snippet hslice
|
|
|
|
@{ ${1:hash} }{ ${2:array} }
|
|
|
|
|
|
|
|
|
|
|
|
# map
|
|
|
|
snippet map
|
|
|
|
map { ${2: body } } ${1: @array } ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Pod stub
|
|
|
|
snippet ppod
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
${1:ClassName} - ${2:ShortDesc}
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
use $1;
|
|
|
|
|
|
|
|
${3:# synopsis...}
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
${4:# longer description...}
|
|
|
|
|
|
|
|
|
|
|
|
=head1 INTERFACE
|
|
|
|
|
|
|
|
|
|
|
|
=head1 DEPENDENCIES
|
|
|
|
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
|
|
|
|
|
|
|
# Heading for a subroutine stub
|
|
|
|
snippet psub
|
|
|
|
=head2 ${1:MethodName}
|
|
|
|
|
|
|
|
${2:Summary....}
|
|
|
|
|
2012-03-10 14:58:12 -05:00
|
|
|
# Heading for inline subroutine pod
|
|
|
|
snippet psubi
|
|
|
|
=head2 ${1:MethodName}
|
|
|
|
|
|
|
|
${2:Summary...}
|
|
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2011-09-09 12:57:55 -04:00
|
|
|
|
|
|
|
# Subroutine signature
|
|
|
|
snippet parg
|
|
|
|
=over 2
|
|
|
|
|
|
|
|
=item
|
|
|
|
Arguments
|
|
|
|
|
|
|
|
|
|
|
|
=over 3
|
|
|
|
|
|
|
|
=item
|
|
|
|
C<${1:DataStructure}>
|
|
|
|
|
|
|
|
${2:Sample}
|
|
|
|
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
|
|
|
|
=item
|
|
|
|
Return
|
|
|
|
|
|
|
|
=over 3
|
|
|
|
|
|
|
|
|
|
|
|
=item
|
|
|
|
C<${3:...return data}>
|
|
|
|
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Moose has
|
|
|
|
snippet has
|
|
|
|
has ${1:attribute} => (
|
|
|
|
is => '${2:ro|rw}',
|
|
|
|
isa => '${3:Str|Int|HashRef|ArrayRef|etc}',
|
|
|
|
default => ${4:defaultvalue}
|
|
|
|
,${5:# other attributes}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# override
|
|
|
|
snippet override
|
|
|
|
override ${1:attribute} => sub {
|
|
|
|
${2:# my $self = shift;};
|
|
|
|
${3:# my ($self,$args) = @_;};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# use test classes
|
|
|
|
snippet tuse
|
|
|
|
use Test::More;
|
2012-03-10 15:02:04 -05:00
|
|
|
use Test::Deep ();
|
2011-09-09 12:57:55 -04:00
|
|
|
use Test::Exception;
|
|
|
|
|
|
|
|
# local test lib
|
|
|
|
snippet tlib
|
|
|
|
use lib qw{ ./t/lib };
|
|
|
|
|
|
|
|
#test methods
|
|
|
|
snippet tmeths
|
|
|
|
$ENV{TEST_METHOD} = '${1:regex}';
|
|
|
|
|
|
|
|
# runtestclass
|
|
|
|
snippet trunner
|
|
|
|
use ${1:test_class};
|
|
|
|
$1->runtests();
|
|
|
|
|
2012-03-10 15:02:04 -05:00
|
|
|
# Test::Class-style test
|
2011-09-09 12:57:55 -04:00
|
|
|
snippet tsub
|
|
|
|
sub t${1:number}_${2:test_case} :Test(${3:num_of_tests}) {
|
|
|
|
my $self = shift;
|
|
|
|
${4:# body}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-10 15:02:04 -05:00
|
|
|
# Test::Routine-style test
|
|
|
|
snippet trsub
|
|
|
|
test ${1:test_name} => { description => '${2:Description of test.}'} => sub {
|
|
|
|
my ($self) = @_;
|
|
|
|
${3:# test code}
|
|
|
|
};
|
2011-09-09 12:57:55 -04:00
|
|
|
|
|
|
|
#prep test method
|
|
|
|
snippet tprep
|
|
|
|
sub prep${1:number}_${2:test_case} :Test(startup) {
|
|
|
|
my $self = shift;
|
|
|
|
${4:# body}
|
|
|
|
}
|
2011-11-24 07:38:52 -05:00
|
|
|
# cause failures to print stack trace
|
|
|
|
snippet debug_trace
|
|
|
|
use Carp; # 'verbose';
|
|
|
|
# cloak "die"
|
|
|
|
# warn "warning"
|
|
|
|
$SIG{'__DIE__'} = sub {
|
|
|
|
require Carp; Carp::confess
|
|
|
|
};
|
|
|
|
|