| 1 | # | ||
| 2 | # This file is part of ModuleUnderscore | ||
| 3 | # | ||
| 4 | # This software is copyright (c) 2014 by celogeek <me@celogeek.com>. | ||
| 5 | # | ||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||
| 8 | # | ||
| 9 | package Module::Underscore; | ||
| 10 | |||
| 11 | # ABSTRACT: convert module name to underscore string name and underscore string name to module name | ||
| 12 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 3 | our $VERSION = '0.4'; # VERSION | |
| 15 | 3 | ▶ | use base 'Exporter'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | |||
| 17 | 3 | our @EXPORT_OK = qw( | |
| 18 | underscore_to_module | ||
| 19 | module_to_underscore | ||
| 20 | ); | ||
| 21 | |||
| 22 | 3 | our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); | |
| 23 | |||
| 24 | 8 | ▶ | sub underscore_to_module { |
|
Subroutine
underscore_to_module: called CC=1 SCAR=0.0
Pod
documented
| |||
| 25 | 8 | my ($underscore_string) = @_; | |
| 26 | 8 | my $module_string = lc($underscore_string); | |
| 27 | 8 | $module_string =~ s/[^a-z0-9]+(.?)/::\u$1/gx; | |
| 28 | 8 | $module_string = ucfirst($module_string); | |
| 29 | |||
| 30 | 8 | return $module_string; | |
| 31 | } | ||
| 32 | |||
| 33 | 5 | ▶ | sub module_to_underscore { |
|
Subroutine
module_to_underscore: called CC=1 SCAR=0.0
Pod
documented
| |||
| 34 | 5 | my ($module_string) = @_; | |
| 35 | |||
| 36 | 5 | my $underscore_string = lc($module_string); | |
| 37 | 5 | $underscore_string =~ s/[^a-z0-9]+/_/gx; | |
| 38 | |||
| 39 | 5 | return $underscore_string; | |
| 40 | } | ||
| 41 | |||
| 42 | 3 | 1; | |
| 43 | |||
| 44 | __END__ | ||