root/capitalization/trunk/capitalization.pm

Revision 836 (checked in by miyagawa, 17 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package capitalization;
2
3 use strict;
4 use vars qw($VERSION);
5 $VERSION = 0.01;
6
7 use Devel::Symdump;
8
9 my %done;
10
11 sub unimport {
12     my($class, @mods) = @_;
13     for my $mod (@mods) {
14         next if $done{$mod};
15
16         my $file = mod2file($mod);
17         require $file unless $INC{$file};
18
19         my $dump = Devel::Symdump->new($mod);
20         for my $meth (map { s/^\Q$mod\E:://; $_ } $dump->functions) {
21             my $new = nocap($meth);
22             if ($new ne $meth) {
23                 no strict 'refs';
24                 *{"$mod\::$new"} = \&{"$mod\::$meth"};
25             }
26         }
27         $done{$mod} = 1;
28     }
29 }
30
31 sub nocap {
32     my $method = shift;
33     $method =~ s/(?<=[a-z])([A-Z]+)/"_" . lc($1)/eg;
34     lcfirst $method;
35 }
36
37 sub mod2file {
38     my $mod = shift;
39     $mod =~ s!::!/!g;
40     return "$mod.pm";
41 }
42
43 1;
44 __END__
45
46 =head1 NAME
47
48 capitalization - no capitalization on method names
49
50 =head1 SYNOPSIS
51
52   use XML::DOM;
53   no capitalization 'XML::DOM';
54
55   my $parser = XML::DOM::Parser->new;
56
57   # no capitalization ..
58   my $nodes = $parser->get_elements_by_tag_name("Foo");
59
60   # this can be OK
61   my $nodes = $parser->getElementsByTagName("Foo");
62
63
64 =head1 DESCRIPTION
65
66 capitalization.pm allows you to use familiar style on method naming.
67
68 =head1 AUTHOR
69
70 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
71
72 This library is free software; you can redistribute it and/or modify
73 it under the same terms as Perl itself.
74
75 =head1 SEE ALSO
76
77 L<Symbol::Approx::Sub>
78
79 =cut
Note: See TracBrowser for help on using the browser.