| 1 | # | ||
| 2 | # This file is part of autobox-Camelize | ||
| 3 | # | ||
| 4 | # This software is Copyright (c) 2012 by Chris Weyl. | ||
| 5 | # | ||
| 6 | # This is free software, licensed under: | ||
| 7 | # | ||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||
| 9 | # | ||
| 10 | package autobox::Camelize; | ||
| 11 | { | ||
| 12 | 2 | $autobox::Camelize::VERSION = '0.001'; | |
| 13 | } | ||
| 14 | |||
| 15 | # ABSTRACT: autobox methods for (de)camelcasing | ||
| 16 | |||
| 17 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 2 | ▶ | use parent 'autobox'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | |||
| 22 | 1 | ▶ | sub import { |
|
Subroutine
import: called CC=1 SCAR=0.0
| |||
| 23 | 1 | my $class = shift @_; | |
| 24 | |||
| 25 | 1 | return $class->SUPER::import( | |
| 26 | STRING => 'autobox::Camelize::STRING', | ||
| 27 | @_, | ||
| 28 | ); | ||
| 29 | } | ||
| 30 | |||
| 31 | { | ||
| 32 | package autobox::Camelize::STRING; | ||
| 33 | { | ||
| 34 | 2 | $autobox::Camelize::STRING::VERSION = '0.001'; | |
| 35 | } | ||
| 36 | |||
| 37 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 38 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 39 | |||
| 40 | 2 | ▶ | sub decamelize { |
|
Subroutine
decamelize: called CC=1 SCAR=0.0
| |||
| 41 | 2 | my $string = lcfirst shift @_; | |
| 42 | |||
| 43 | 2 | $string =~ s/::(.)/__\l$1/g; | |
| 44 | 2 | $string =~ s/([A-Z])/_\l$1/g; | |
| 45 | |||
| 46 | 2 | return $string; | |
| 47 | } | ||
| 48 | |||
| 49 | 2 | ▶ | sub camelize { |
|
Subroutine
camelize: called CC=1 SCAR=0.0
| |||
| 50 | 2 | my $string = ucfirst shift @_; | |
| 51 | |||
| 52 | 2 | $string =~ s/__(.)/::\u$1/g; | |
| 53 | 2 | $string =~ s/_(.)/\u$1/g; | |
| 54 | |||
| 55 | 2 | return $string; | |
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | 2 | !!42; | |
| 60 | |||
| 61 | __END__ | ||