File Coverage

blib/lib/lambda.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 32 32 100.0


line stmt bran cond sub pod time code
1             package lambda;
2             $VERSION = v0.0.1;
3              
4 2     2   24635 use warnings;
  2         5  
  2         78  
5 2     2   13 use strict;
  2         3  
  2         95  
6              
7             =encoding utf8
8              
9             =head1 NAME
10              
11             lambda - a shortcut for sub {...}
12              
13             =head1 SYNOPSIS
14              
15             Instead of:
16              
17             my $code = sub {...};
18              
19             Just:
20              
21             my $code = λ{...};
22              
23             Note: If your perldoc (or terminal (or browser)) isn't properly
24             rendering unicode, the above looks like an 'I' followed by a double
25             arrow (or maybe just an 'X'.) It is a unicode lowercase lambda (0x3BB.)
26              
27             =head1 utf8
28              
29             This module has import() and unimport() methods which mimic utf8.pm.
30             Thus, instead of saying 'C', you can simply say
31             'C'.
32              
33             The caveat to this is that 'C' also means 'C'. I
34             blame C<$^H> (suggestions welcome, and yes 5.10 might require this to
35             change.)
36              
37             =head1 VIM SHORTCUT
38              
39             My .vimrc has:
40              
41             imap λ{}:set encoding=utf8i
42              
43             In insert mode (only), this types the lambda and matching braces, sets
44             the encoding, then puts your cursor between the braces.
45              
46             =cut
47              
48 2     2   2152 use utf8;
  2         26  
  2         14  
49              
50             sub import {
51 4     4   1914 $^H |= $utf8::hint_bits;
52 4         10 my $callpkg = caller();
53 2     2   129 no strict 'refs';
  2         3  
  2         213  
54 4     2   16 *{$callpkg . '::' . 'λ'} = sub (&) {$_[0]};
  4         264  
  2         33  
55             }
56              
57             sub unimport {
58 2     2   13 $^H &= ~$utf8::hint_bits;
59 2         5 my $callpkg = caller();
60 2     2   10 no strict 'refs';
  2         5  
  2         136  
61 2         2 delete ${$callpkg . '::'}{'λ'};
  2         86  
62             }
63              
64             =head1 Methods
65              
66             =head2 import
67              
68             Puts λ in your symbol table, turns on utf8 parsing.
69              
70             =head2 unimport
71              
72             Removes λ from your symbol table, turns off utf8 parsing.
73              
74             =head1 AUTHOR
75              
76             Eric Wilhelm @
77              
78             http://scratchcomputing.com/
79              
80             =head1 BUGS
81              
82             If you found this module on CPAN, please report any bugs or feature
83             requests through the web interface at L. I will be
84             notified, and then you'll automatically be notified of progress on your
85             bug as I make changes.
86              
87             If you pulled this development version from my /svn/, please contact me
88             directly.
89              
90             =head1 COPYRIGHT
91              
92             Copyright (C) 2007 Eric L. Wilhelm, All Rights Reserved.
93              
94             =head1 NO WARRANTY
95              
96             Absolutely, positively NO WARRANTY, neither express or implied, is
97             offered with this software. You use this software at your own risk. In
98             case of loss, no person or entity owes you anything whatsoever. You
99             have been warned.
100              
101             =head1 LICENSE
102              
103             This program is free software; you can redistribute it and/or modify it
104             under the same terms as Perl itself.
105              
106             =cut
107              
108             # vi:ts=2:sw=2:et:sta:encoding=utf8
109             1;