File: Util.pm

package info (click to toggle)
libdbix-dr-perl 0.19-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 340 kB
  • sloc: perl: 1,621; makefile: 548
file content (53 lines) | stat: -rw-r--r-- 976 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use utf8;
use strict;
use warnings;

package DBIx::DR::Util;

use base qw(Exporter);
our @EXPORT = qw(camelize decamelize);


sub camelize($) {
    my ($str) = @_;

    my ($module, $method) = split /#/, $str;

    $module =
        join '', map { ucfirst } split /_/,
            join '::' => map { ucfirst lc } split /-/ => $module;

    $module =~ s/dbix::dr::/DBIx::DR::/i;

    return ($module, $method);
}


sub decamelize($;$) {
    my ($class, $constructor) = @_;
    for ($class) {
        s/(?<!^)[A-Z]/_$&/g;
        s/::_/::/g;
        s/::/-/g;
    }

    return lc $class unless $constructor;
    return lc($class) . "#$constructor";
}

1;

=head1 NAME

DBIx::DR::Util - some functions for L<DBIx::DR>.

=head1 COPYRIGHT

 Copyright (C) 2011 Dmitry E. Oboukhov <unera@debian.org>
 Copyright (C) 2011 Roman V. Nikolaev <rshadow@rambler.ru>

 This program is free software, you can redistribute it and/or
 modify it under the terms of the Artistic License.

=cut