prole snippet
[gitmo/moose-dev-utils.git] / vim / moose_snippets.vim
CommitLineData
bb2ea7b7 1" See http://www.vim.org/scripts/script.php?script_id=1318
9f4e6b22 2" Written by Sartak and doy, feel free to add your own!
bb2ea7b7 3
4if !exists('loaded_snippet') || &cp
5 finish
6endif
7
f93358a2 8function! RemoveEmptySuperClass()
9a5242eb 9 s/^extends '<{}>';\n//e
10 return @z
11endfun
12
f93358a2 13function! RemoveEmptyLine()
a55ef827 14 s/^\s*<{}>\s*\n//e
15 return @z
16endfun
17
f93358a2 18function! Snippet(abbr, str)
9e14e28f 19 if type(a:str) == type([])
20 return Snippet(a:abbr, join(a:str, "\n"))
21 endif
22 let st = g:snip_start_tag
23 let et = g:snip_end_tag
24 let cd = g:snip_elem_delim
25 let str = substitute(a:str, '<{.\{-}\zs:\ze.\{-}}>', cd, "")
26 let str = substitute(str, '<{', st, "")
27 let str = substitute(str, '}>', et, "")
28 exec 'Snippet '.a:abbr.' '.str
29endfunction
30
f93358a2 31function! SnippetFile(filename)
9e14e28f 32 let abbr = fnamemodify(a:filename, ':t:r')
33 let str = readfile(a:filename)
34 return Snippet(abbr, str)
35endfunction
36
37call Snippet('class', [
38 \"package <{ClassName}>;",
39 \"use Moose;",
40 \"",
41 \"extends '<{SuperClass:RemoveEmptySuperClass()}>;",
42 \"",
43 \"<{}>",
44 \"",
45 \"__PACKAGE__->meta->make_immutable;",
46 \"no Moose;",
47 \"",
48 \"1;"])
49ac30b5 49call Snippet('role', [
50 \"package <{RoleName}>;",
51 \"use Moose::Role;",
52 \"",
53 \"<{}>",
54 \"",
55 \"no Moose::Role;",
56 \"",
57 \"1;"])
9e14e28f 58call Snippet('has', [
59 \"has <{attr}> => (",
60 \ "is => '<{rw}>',",
61 \ "isa => '<{Str}>',",
a55ef827 62 \ "<{options:RemoveEmptyLine()}>",
9e14e28f 63 \");"])
64call Snippet('hasl', [
65 \"has <{attr}> => (",
66 \ "is => '<{rw}>',",
67 \ "isa => '<{Str}>',",
68 \ "lazy_build => 1,",
a55ef827 69 \ "<{options:RemoveEmptyLine()}>",
9e14e28f 70 \");",
71 \"",
a75bdf8d 72 \"sub _build_<{attr}> {",
9e14e28f 73 \ "my $self = shift;",
74 \ "<{}>",
75 \"}"])
76call Snippet('sub', [
77 \"sub <{name}> {",
78 \ "my $self = shift;",
79 \ "<{}>",
80 \"}"])
81call Snippet('around', [
82 \"around <{name}> => sub {",
babbac06 83 \ "my $<{next}> = shift;",
9e14e28f 84 \ "my $self = shift;",
85 \ "<{}>",
86 \"};"])
9ac2672c 87call Snippet('before', [
88 \"before <{name}> => sub {",
89 \ "my $self = shift;",
90 \ "<{}>",
91 \"};"])
92call Snippet('after', [
93 \"after <{name}> => sub {",
94 \ "my $self = shift;",
95 \ "<{}>",
96 \"};"])
bb2ea7b7 97
41348999 98" MooseX support
99call Snippet('prole', [
100 \"package <{RoleName}>;",
101 \"use MooseX::Role::Parameterized;",
102 \"",
103 \"<{}>",
104 \"",
105 \"role {",
106 \"my $p = shift;",
107 \"",
108 \"<{}>",
109 \"};",
110 \"",
111 \"no MooseX::Role::Parameterized;",
112 \"",
113 \"1;"])
114
9e14e28f 115"for file in globpath(&rtp, 'snippets/*')
116 "call SnippetFile(file)
117"endfor