Added Catalyst::Utils
Sebastian Riedel [Sat, 16 Apr 2005 17:28:18 +0000 (17:28 +0000)]
Changes
lib/Catalyst/Dispatcher.pm
lib/Catalyst/Engine.pm
lib/Catalyst/Utils.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index 61c565f..ae17303 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,7 @@ This file documents the revision history for Perl extension Catalyst.
 
 5.01  XXX Apr XX XX:00:00 2005
         - some documentation bugs fixed
+        - added Catalyst::Utils
 
 5.00  Fri Apr 15 18:00:00 2005
         - new core to support inheritance trees
index 22e648a..861d5ef 100644 (file)
@@ -2,7 +2,7 @@ package Catalyst::Dispatcher;
 
 use strict;
 use base 'Class::Data::Inheritable';
-use Memoize;
+use Catalyst::Utils;
 use Text::ASCIITable;
 use Tree::Simple;
 use Tree::Simple::Visitor::FindByPath;
@@ -17,8 +17,6 @@ __PACKAGE__->actions(
 # We use a tree
 __PACKAGE__->tree( Tree::Simple->new( 0, Tree::Simple->ROOT ) );
 
-memoize('_class2prefix');
-
 =head1 NAME
 
 Catalyst::Dispatcher - The Catalyst Dispatcher
@@ -48,7 +46,8 @@ sub dispatch {
 
     unless ($namespace) {
         if ( my $result = $c->get_action($action) ) {
-            $namespace = _class2prefix( $result->[0]->[0]->[0] );
+            $namespace =
+              Catalyst::Utils::class2prefix( $result->[0]->[0]->[0] );
         }
     }
 
@@ -130,7 +129,7 @@ sub forward {
         $command =~ s/^\///;
     }
 
-    else { $namespace = _class2prefix($caller) || '/' }
+    else { $namespace = Catalyst::Utils::class2prefix($caller) || '/' }
 
     my $results = $c->get_action( $command, $namespace );
 
@@ -260,7 +259,7 @@ Set an action in a given namespace.
 sub set_action {
     my ( $c, $method, $code, $namespace, $attrs ) = @_;
 
-    my $prefix = _class2prefix($namespace) || '';
+    my $prefix = Catalyst::Utils::class2prefix($namespace) || '';
     my %flags;
 
     for my $attr ( @{$attrs} ) {
@@ -442,23 +441,6 @@ sub setup_actions {
       if ( @{ $regexes->{tbl_rows} } && $self->debug );
 }
 
-sub _prefix {
-    my ( $class, $name ) = @_;
-    my $prefix = _class2prefix($class);
-    $name = "$prefix/$name" if $prefix;
-    return $name;
-}
-
-sub _class2prefix {
-    my $class = shift || '';
-    my $prefix;
-    if ( $class =~ /^.*::([MVC]|Model|View|Controller)?::(.*)$/ ) {
-        $prefix = lc $2;
-        $prefix =~ s/\:\:/\//g;
-    }
-    return $prefix;
-}
-
 =back
 
 =head1 AUTHOR
index 486bbf7..e4f22da 100644 (file)
@@ -678,9 +678,6 @@ sub stash {
     return $self->{stash};
 }
 
-# Takes a coderef and returns an arrayref containing attributes
-sub _get_attrs { attributes::get( $_[0] ) || [] }
-
 =back
 
 =head1 AUTHOR
diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm
new file mode 100644 (file)
index 0000000..89fbd4d
--- /dev/null
@@ -0,0 +1,70 @@
+package Catalyst::Utils;
+
+use strict;
+use attributes ();
+
+=head1 NAME
+
+Catalyst::Utils - The Catalyst Utils
+
+=head1 SYNOPSIS
+
+See L<Catalyst>.
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=over 4
+
+=item attrs($coderef)
+
+Returns attributes for coderef in a arrayref
+
+=cut
+
+sub attrs { attributes::get( $_[0] ) || [] }
+
+=item prefix($class, $name);
+
+Returns a prefixed action.
+
+=cut
+
+sub prefix {
+    my ( $class, $name ) = @_;
+    my $prefix = &class2prefix($class);
+    $name = "$prefix/$name" if $prefix;
+    return $name;
+}
+
+=item class2prefix($class);
+
+Returns the prefix for class.
+
+=cut
+
+sub class2prefix {
+    my $class = shift || '';
+    my $prefix;
+    if ( $class =~ /^.*::([MVC]|Model|View|Controller)?::(.*)$/ ) {
+        $prefix = lc $2;
+        $prefix =~ s/\:\:/\//g;
+    }
+    return $prefix;
+}
+
+=back
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri@cpan.org>
+
+=head1 COPYRIGHT
+
+This program is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
+
+1;