From a527891868a3d8ef3e0001fa9383fac186b0c6df Mon Sep 17 00:00:00 2001 From: William Travis Holton Date: Fri, 9 Sep 2011 18:57:55 +0200 Subject: [PATCH] Some custom perl snippets These were previously in separate files. I appended them to the main perl.snippets file. --- snippets/perl.snippets | 236 ++++++++++++++++++++++ snippets/perl/perl-basic.snippets | 158 --------------- snippets/perl/perl-moosesnippets.snippets | 50 ----- snippets/perl/perl-test.snippets | 36 ---- 4 files changed, 236 insertions(+), 244 deletions(-) delete mode 100644 snippets/perl/perl-basic.snippets delete mode 100644 snippets/perl/perl-moosesnippets.snippets delete mode 100644 snippets/perl/perl-test.snippets diff --git a/snippets/perl.snippets b/snippets/perl.snippets index 381831f..4d1e941 100644 --- a/snippets/perl.snippets +++ b/snippets/perl.snippets @@ -95,3 +95,239 @@ snippet cl snippet slurp my $${1:var} = do { local $/; open my $file, '<', "${2:file}"; <$file> }; ${3} + + +# 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 + __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/ + ${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....} + + +# 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 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...} + + +# 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; + 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}) { + my $self = shift; + ${4:# body} + + } + + +#prep test method +snippet tprep + sub prep${1:number}_${2:test_case} :Test(startup) { + my $self = shift; + ${4:# body} + } diff --git a/snippets/perl/perl-basic.snippets b/snippets/perl/perl-basic.snippets deleted file mode 100644 index f5ec1cf..0000000 --- a/snippets/perl/perl-basic.snippets +++ /dev/null @@ -1,158 +0,0 @@ -# #!/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 - - -# 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 - __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/ - ${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....} - - -# 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/perl-moosesnippets.snippets b/snippets/perl/perl-moosesnippets.snippets deleted file mode 100644 index a731ec5..0000000 --- a/snippets/perl/perl-moosesnippets.snippets +++ /dev/null @@ -1,50 +0,0 @@ -# #!/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} - ); - - -# override -snippet override - override ${1:attribute} => sub { - ${2:# my $self = shift;}; - ${3:# my ($self,$args) = @_;}; - }; - - - - - diff --git a/snippets/perl/perl-test.snippets b/snippets/perl/perl-test.snippets deleted file mode 100644 index 7e25517..0000000 --- a/snippets/perl/perl-test.snippets +++ /dev/null @@ -1,36 +0,0 @@ -# #!/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}) { - my $self = shift; - ${4:# body} - - } - - -#prep test method -snippet tprep - sub prep${1:number}_${2:test_case} :Test(startup) { - my $self = shift; - ${4:# body} - }