From bfc34d3713f829d9d6483bc11b1ffa6137b5a566 Mon Sep 17 00:00:00 2001 From: William Travis Holton Date: Mon, 27 Jun 2011 22:13:31 +0200 Subject: [PATCH 1/3] shortcuts for various Perl constructs --- snippets/perl-basic.snippets | 58 ++++++++++++++++++++++++++++ snippets/perl-moosesnippets.snippets | 37 ++++++++++++++++++ snippets/perl-test.snippets | 29 ++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 snippets/perl-basic.snippets create mode 100644 snippets/perl-moosesnippets.snippets create mode 100644 snippets/perl-test.snippets diff --git a/snippets/perl-basic.snippets b/snippets/perl-basic.snippets new file mode 100644 index 0000000..68988e1 --- /dev/null +++ b/snippets/perl-basic.snippets @@ -0,0 +1,58 @@ +# #!/usr/bin/perl + +# 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 + + + +# Anonymous subroutine +snippet asub + sub { + ${1:# body } + } + + +# Begin block +snippet begin + BEGIN { #{{{ + ${1:# begin body} + } #}}} + +# call package function +snippet pkgm + __PACKAGE__->${1:package_method}(${2:var}); + +# complex regex +snippet qrx + qr/ + ${1:regex} + /xms + +#simpler regex +snippet qr/ + qr/${1:regex}/x + +#switch +snippet switch + switch ($${1:var}) { #{{{ + ${2:# cases} + } #}}} + +# switch case +snippet case + case ${1:case} { + ${2:# body} + } + + + diff --git a/snippets/perl-moosesnippets.snippets b/snippets/perl-moosesnippets.snippets new file mode 100644 index 0000000..145038c --- /dev/null +++ b/snippets/perl-moosesnippets.snippets @@ -0,0 +1,37 @@ +# #!/usr/bin/perl + +# Moose package +snippet moosecl + package ${1:ClassName}; + + use Moose; + #extends ${2:# ParentClass}; + + ${6:# body of class} + + 1; + __END__ + + =head1 NAME + + $1 - ${3:ShortDesc} + + =head1 SYNOPSIS + + ${4:# synopsis...} + + =head1 DESCRIPTION + + ${5:# longer description...} + + +# has +snippet has + has ${1:attribute} => ( #{{{ + is => '${2:ro|rw}', + isa => '${3:Str|Int|HashRef|ArrayRef|etc}', + default => ${4:defaultvalue} + ,${5:# other attributes} + ); #}}} + + diff --git a/snippets/perl-test.snippets b/snippets/perl-test.snippets new file mode 100644 index 0000000..31e0905 --- /dev/null +++ b/snippets/perl-test.snippets @@ -0,0 +1,29 @@ +# #!/usr/bin/perl + +# use test classes +snippet tuse + use Test::More; + use Test::Deep; + 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(); + +#testclass +snippet tsub + sub t${1:number}_${2:test_case} Test:(${3:num_of_tests}) { #{{{ + ${4:# body} + + } #}}} + + From 1acd1e803a49585c0d42091e6e3d72ecb1853747 Mon Sep 17 00:00:00 2001 From: William Travis Holton Date: Mon, 27 Jun 2011 22:32:23 +0200 Subject: [PATCH 2/3] modify with some updated features --- snippets/perl-basic.snippets | 118 +++++++++++++++++++++++++-- snippets/perl-moosesnippets.snippets | 14 +++- snippets/perl-test.snippets | 9 +- 3 files changed, 130 insertions(+), 11 deletions(-) diff --git a/snippets/perl-basic.snippets b/snippets/perl-basic.snippets index 68988e1..d561dee 100644 --- a/snippets/perl-basic.snippets +++ b/snippets/perl-basic.snippets @@ -14,6 +14,11 @@ snippet vers ## use critic +# new 'switch' like feature +snippet switch + use feature 'switch'; + + # Anonymous subroutine snippet asub @@ -22,16 +27,29 @@ snippet asub } + # Begin block snippet begin BEGIN { #{{{ ${1:# begin body} } #}}} -# call package function -snippet pkgm +# call package function with some parameter +snippet pkgmv __PACKAGE__->${1:package_method}(${2:var}); +# call package function without a parameter +snippet pkgm + __PACKAGE__->${1:package_method}(); + +# call package "get_" function without a parameter +snippet pkget + __PACKAGE__->get_${1:package_method}(); + +# call package function with a parameter +snippet pkgetv + __PACKAGE__->get_${1:package_method}(${2:var}); + # complex regex snippet qrx qr/ @@ -42,17 +60,99 @@ snippet qrx snippet qr/ qr/${1:regex}/x -#switch -snippet switch - switch ($${1:var}) { #{{{ +#given +snippet given + given ($${1:var}) { #{{{ ${2:# cases} + ${3:# default} } #}}} -# switch case -snippet case - case ${1:case} { +# 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....} + + +# 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 + diff --git a/snippets/perl-moosesnippets.snippets b/snippets/perl-moosesnippets.snippets index 145038c..cb99a15 100644 --- a/snippets/perl-moosesnippets.snippets +++ b/snippets/perl-moosesnippets.snippets @@ -9,7 +9,8 @@ snippet moosecl ${6:# body of class} - 1; + "one, but we're not the same"; + __END__ =head1 NAME @@ -35,3 +36,14 @@ snippet has ); #}}} +# override +snippet override + override ${1:attribute} => sub { #{{{ + ${2:# my $self = shift;}; + ${3:# my ($self,$args) = @_;}; + }; #}}} + + + + + diff --git a/snippets/perl-test.snippets b/snippets/perl-test.snippets index 31e0905..da9f829 100644 --- a/snippets/perl-test.snippets +++ b/snippets/perl-test.snippets @@ -21,9 +21,16 @@ snippet trunner #testclass snippet tsub - sub t${1:number}_${2:test_case} Test:(${3:num_of_tests}) { #{{{ + sub t${1:number}_${2:test_case} :Test(${3:num_of_tests}) { #{{{ + my $self = shift; ${4:# body} } #}}} +#prep test method +snippet tprep + sub prep${1:number}_${2:test_case} :Test(startup) { #{{{ + my $self = shift; + ${4:# body} + } #}}} From 38ea21ddadf73258e3e704e4602ee1087aa19f56 Mon Sep 17 00:00:00 2001 From: William Travis Holton Date: Mon, 27 Jun 2011 22:38:45 +0200 Subject: [PATCH 3/3] change back to the traditional 1; end thing --- snippets/perl-moosesnippets.snippets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snippets/perl-moosesnippets.snippets b/snippets/perl-moosesnippets.snippets index cb99a15..efad9cc 100644 --- a/snippets/perl-moosesnippets.snippets +++ b/snippets/perl-moosesnippets.snippets @@ -9,7 +9,8 @@ snippet moosecl ${6:# body of class} - "one, but we're not the same"; + 1; + __END__