| 1 | package lambda; | ||
| 2 | 2 | $VERSION = v0.0.1; | |
| 3 | |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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<use utf8; use lambda;>', you can simply say | ||
| 31 | 'C<use lambda;>'. | ||
| 32 | |||
| 33 | The caveat to this is that 'C<no lambda;>' also means 'C<no utf8;>'. 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 <C-S-L> λ{}<ESC>:set encoding=utf8<CR>i | ||
| 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 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 49 | |||
| 50 | 4 | ▶ | sub import { |
|
Subroutine
import: called CC=1 SCAR=0.0
| |||
| 51 | 4 | $^H |= $utf8::hint_bits; | |
| 52 | 4 | my $callpkg = caller(); | |
| 53 | 2 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 54 | 0 | ▶ | *{$callpkg . '::' . 'λ'} = sub (&) {$_[0]}; |
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||
| 55 | } | ||
| 56 | |||
| 57 | 0 | ▶ | sub unimport { |
|
Subroutine
unimport: not called CC=1 SCAR=1.7
| |||
| 58 | 0 | $^H &= ~$utf8::hint_bits; | |
| 59 | 0 | my $callpkg = caller(); | |
| 60 | 2 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 61 | 0 | delete ${$callpkg . '::'}{'λ'}; | |
| 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 @ <ewilhelm at cpan dot org> | ||
| 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<http://rt.cpan.org>. 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 | 2 | 1; | |