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