capitalization - no capitalization on method names


capitalization documentation Contained in the capitalization distribution.

Index


Code Index:

NAME

Top

capitalization - no capitalization on method names

SYNOPSIS

Top

  use XML::DOM;
  no capitalization 'XML::DOM';

  my $parser = XML::DOM::Parser->new;

  # no capitalization ..
  my $nodes = $parser->get_elements_by_tag_name("Foo");

  # this can be OK
  my $nodes = $parser->getElementsByTagName("Foo");




DESCRIPTION

Top

capitalization.pm allows you to use familiar style on method naming.

RULES

Top

Lower case character followed by upper case sequence would be splitted with _ and upper case sequence would be lower cased. Example: fooBar would be foo_bar.
All other upper case characters would be lower cased. Examples: FOOs would be foos, _Foo would be _foo.

CAVEATS

Top

no capitalization __PACKAGE__;

If you want use capitalization pragma in module and add lower case API in the module itself, then you should use pragma after all subs are defined.

AUTHOR

Top

Tatsuhiko Miyagawa <miyagawa@bulknews.net>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Top

Symbol::Approx::Sub


capitalization documentation Contained in the capitalization distribution.

package capitalization;

use strict;
use vars qw($VERSION);
$VERSION = 0.03;

use Devel::Symdump;

my %done;

sub unimport {
    my($class, @mods) = @_;
    for my $mod (@mods) {
	next if $done{$mod};

	my $file = mod2file($mod);
	require $file unless $INC{$file};

	my $dump = Devel::Symdump->new($mod);
	for my $meth (map { s/^\Q$mod\E:://; $_ } $dump->functions) {
	    my $new = nocap($meth);
	    if ($new ne $meth) {
		no strict 'refs';
		*{"$mod\::$new"} = \&{"$mod\::$meth"};
	    }
	}
	$done{$mod} = 1;
    }
}

sub nocap {
    my $method = shift;
    $method =~ s/(?<=[a-z])([A-Z]+)/"_" . lc($1)/eg;
    $method =~ tr/A-Z/a-z/;
    return $method;
}

sub mod2file {
    my $mod = shift;
    $mod =~ s!::!/!g;
    return "$mod.pm";
}

1;
__END__