summaryrefslogtreecommitdiffstats
path: root/vim/snippets/perl.snippets
blob: 0478676b7e38fca7bda9d167b675801632296805 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
snippet try
	try {
	    ${1}
	} catch {
	    ${2}
	};
snippet st
	map  { $_->[0] }
	sort { $a->[1] ${3:cmp} $b->[1] }
	map  { [$_, ${2:function}] }
	${1:list}
snippet tbl
	local $Test::Builder::Level = $Test::Builder::Level + 1;
snippet ccl
	local $Carp::CarpLevel = $Carp::CarpLevel + 1;
snippet linc
	local $${1:a} = $$1 + ${2:1};
	${3}
snippet script
	#!/usr/bin/env perl
	use strict;
	use warnings;

snippet test
	#!/usr/bin/env perl
	use strict;
	use warnings;
	use Test::More;

	${1}

	done_testing;
snippet nac
	use namespace::autoclean;
snippet dd
	use Data::Dumper; die Dumper(${1});
snippet ddd
	use Data::Dumper; $Data::Dumper::Maxdepth = ${1:1}; die Dumper(${2});
snippet wd
	use Data::Dumper; warn Dumper(${1});
snippet wdd
	use Data::Dumper; $Data::Dumper::Maxdepth = ${1:1}; warn Dumper(${2});
snippet package
	package ${1:`substitute(matchstr(expand("%"), '^lib/\zs.*\ze\.pm'), '/', '::', 'g')`};
	use strict;
	use warnings;

	${2}

	1;
#
# Moose
#
snippet class
	package ${1:`substitute(matchstr(expand("%"), '^lib/\zs.*\ze\.pm'), '/', '::', 'g')`};
	use Moose;

	${2}

	__PACKAGE__->meta->make_immutable;
	no Moose;

	1;
# XXX: ideally, this would be merged with the one above, but we need posthooks
# for that to happen. also, some way to get the extends line to update with
# the package line would be nice, maybe?
snippet subclass
	package ${1:`substitute(matchstr(expand("%"), '^lib/\zs.*\ze\.pm'), '/', '::', 'g')`};
	use Moose;
	extends '${2:`matchstr(substitute(matchstr(expand("%"), '^lib/\zs.*\ze\.pm'), '/', '::', 'g'), '.*\ze::.*')`}';

	${3}

	__PACKAGE__->meta->make_immutable;
	no Moose;

	1;
snippet role
	package ${1:`substitute(matchstr(expand("%"), '^lib/\zs.*\ze\.pm'), '/', '::', 'g')`};
	use Moose::Role;

	${2}

	no Moose::Role;

	1;
snippet has
	has ${1:attr} => (
		is  => '${2:ro}',
		isa => '${3:Str}',${4}
	);
snippet hasl
	has ${1:attr} => (
		is         => '${2:ro}',
		isa        => '${3:Str}',
		lazy_build => 1,${4}
	);

	sub _build_$1 {
		my $self = shift;
		${5}
	}
snippet m
	sub ${1:foo} {
		my $self = shift;
		${2}
	}
snippet around
	around ${1:foo} => sub {
		my $orig = shift;
		my $self = shift;
		${2}
	};
snippet after
	after ${1:foo} => sub {
		my $self = shift;
		${2}
	};
snippet before
	before ${1:foo} => sub {
		my $self = shift;
		${2}
	};