Small config and highlightning changes
[my-vim-dotfolder.git] / snippets / perl.snippets
blobcf8f9fc8567caeb0785d020f47cf76b7b6c8fb69
1 # #!/usr/bin/perl
2 snippet #!
3         #!/usr/bin/perl
4         
5 # Hash Pointer
6 snippet .
7          =>
8 # Function
9 snippet sub
10         sub ${1:function_name} {
11                 ${2:#body ...}
12         }
13 # Conditional
14 snippet if
15         if (${1}) {
16                 ${2:# body...}
17         }
18 # Conditional if..else
19 snippet ife
20         if (${1}) {
21                 ${2:# body...}
22         } else {
23                 ${3:# else...}
24         }
25 # Conditional if..elsif..else
26 snippet ifee
27         if (${1}) {
28                 ${2:# body...}
29         } elsif (${3}) {
30                 ${4:# elsif...}
31         } else {
32                 ${5:# else...}
33         }
34 # Conditional One-line
35 snippet xif
36         ${1:expression} if ${2:condition};${3}
37 # Unless conditional
38 snippet unless
39         unless (${1}) {
40                 ${2:# body...}
41         }
42 # Unless conditional One-line
43 snippet xunless
44         ${1:expression} unless ${2:condition};${3}
45 # Try/Except
46 snippet eval
47         eval {
48                 ${1:# do something risky...}
49         };
50         if ($@) {
51                 ${2:# handle failure...}
52         }
53 # While Loop
54 snippet wh
55         while (${1}) {
56                 ${2:# body...}
57         }
58 # While Loop One-line
59 snippet xwh
60         ${1:expression} while ${2:condition};${3}
61 # For Loop
62 snippet for
63         for (my $${2:var} = 0; $$2 < ${1:count}; $$2${3:++}) {
64                 ${4:# body...}
65         }
66 # Foreach Loop
67 snippet fore
68         foreach my $${1:x} (@${2:array}) {
69                 ${3:# body...}
70         }
71 # Foreach Loop One-line
72 snippet xfore
73         ${1:expression} foreach @${2:array};${3}
74 # Package
75 snippet cl
76         package ${1:ClassName};
77         
78         use base qw(${2:ParentClass});
79         
80         sub new {
81                 my $class = shift;
82                 $class = ref $class if ref $class;
83                 my $self = bless {}, $class;
84                 $self;
85         }
86         
87         1;${3}
88 # Read File
89 snippet slurp
90         my $${1:var};
91         { local $/ = undef; local *FILE; open FILE, "<${2:file}"; $$1 = <FILE>; close FILE }${3}