Added Catalyst::Utils
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Utils.pm
1 package Catalyst::Utils;
2
3 use strict;
4 use attributes ();
5
6 =head1 NAME
7
8 Catalyst::Utils - The Catalyst Utils
9
10 =head1 SYNOPSIS
11
12 See L<Catalyst>.
13
14 =head1 DESCRIPTION
15
16 =head1 METHODS
17
18 =over 4
19
20 =item attrs($coderef)
21
22 Returns attributes for coderef in a arrayref
23
24 =cut
25
26 sub attrs { attributes::get( $_[0] ) || [] }
27
28 =item prefix($class, $name);
29
30 Returns a prefixed action.
31
32 =cut
33
34 sub prefix {
35     my ( $class, $name ) = @_;
36     my $prefix = &class2prefix($class);
37     $name = "$prefix/$name" if $prefix;
38     return $name;
39 }
40
41 =item class2prefix($class);
42
43 Returns the prefix for class.
44
45 =cut
46
47 sub class2prefix {
48     my $class = shift || '';
49     my $prefix;
50     if ( $class =~ /^.*::([MVC]|Model|View|Controller)?::(.*)$/ ) {
51         $prefix = lc $2;
52         $prefix =~ s/\:\:/\//g;
53     }
54     return $prefix;
55 }
56
57 =back
58
59 =head1 AUTHOR
60
61 Sebastian Riedel, C<sri@cpan.org>
62
63 =head1 COPYRIGHT
64
65 This program is free software, you can redistribute it and/or modify it under
66 the same terms as Perl itself.
67
68 =cut
69
70 1;