diff --git a/snippets/perl.snippets b/snippets/perl.snippets index 4ba985d..9cebede 100644 --- a/snippets/perl.snippets +++ b/snippets/perl.snippets @@ -79,48 +79,54 @@ snippet for snippet fore ${1:expression} foreach @${2:array};${3} # Package -snippet cl - package ${1:ClassName}; +snippet package + package ${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`}; - use base qw(${2:ParentClass}); + ${2} - sub new { - my $class = shift; - $class = ref $class if ref $class; - my $self = bless {}, $class; - $self; - } + 1; - 1;${3} + __END__ +# Package syntax perl >= 5.14 +snippet packagev514 + package ${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`} ${2:0.99}; + + ${3} + + 1; + + __END__ +#moose +snippet moose + use Moose; + use namespace::autoclean; + ${1:#}BEGIN {extends '${2:ParentClass}'}; + + ${3} +# parent +snippet parent + use parent qw(${1:Parent Class}); # Read File 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 +# older 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 { + sub { ${1:# body } } @@ -133,19 +139,19 @@ snippet begin } # call package function with some parameter -snippet pkgmv +snippet pkgmv __PACKAGE__->${1:package_method}(${2:var}) # call package function without a parameter -snippet pkgm +snippet pkgm __PACKAGE__->${1:package_method}() # call package "get_" function without a parameter -snippet pkget +snippet pkget __PACKAGE__->get_${1:package_method}() # call package function with a parameter -snippet pkgetv +snippet pkgetv __PACKAGE__->get_${1:package_method}(${2:var}) # complex regex @@ -160,10 +166,10 @@ snippet qr/ #given snippet given - given ($${1:var}) { + given ($${1:var}) { ${2:# cases} ${3:# default} - } + } # switch-like case snippet when @@ -176,7 +182,6 @@ snippet hslice @{ ${1:hash} }{ ${2:array} } - # map snippet map map { ${2: body } } ${1: @array } ; @@ -190,7 +195,7 @@ snippet ppod ${1:ClassName} - ${2:ShortDesc} =head1 SYNOPSIS - + use $1; ${3:# synopsis...} @@ -202,7 +207,7 @@ snippet ppod =head1 INTERFACE - + =head1 DEPENDENCIES @@ -223,8 +228,17 @@ snippet psubi =cut +# inline documented subroutine +snippet subpod + =head2 $1 + Summary of $1 + =cut + + sub ${1:subroutine_name} { + ${2:# body...} + } # Subroutine signature snippet parg =over 2 @@ -232,7 +246,7 @@ snippet parg =item Arguments - + =over 3 =item @@ -255,47 +269,21 @@ snippet parg =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}', + is => '${2:ro|rw}', isa => '${3:Str|Int|HashRef|ArrayRef|etc}', - default => ${4:defaultvalue} - ,${5:# other attributes} + default => sub { + ${4:defaultvalue} + }, + ${5:# other attributes} ); @@ -303,14 +291,14 @@ snippet has snippet override override ${1:attribute} => sub { ${2:# my $self = shift;}; - ${3:# my ($self,$args) = @_;}; + ${3:# my ($self, $args) = @_;}; }; # use test classes snippet tuse use Test::More; - use Test::Deep (); + use Test::Deep; # (); # uncomment to stop prototype errors use Test::Exception; # local test lib @@ -331,7 +319,7 @@ snippet tsub sub t${1:number}_${2:test_case} :Test(${3:num_of_tests}) { my $self = shift; ${4:# body} - + } # Test::Routine-style test @@ -347,6 +335,7 @@ snippet tprep my $self = shift; ${4:# body} } + # cause failures to print stack trace snippet debug_trace use Carp; # 'verbose';