Skip to content

Commit

Permalink
made class_to_file slightly smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 21, 2011
1 parent 8b705e2 commit 89e14c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -5,6 +5,7 @@ This file documents the revision history for Perl extension Mojolicious.
built-in ones.
- Added EXPERIMENTAL support for testing WebSockets with Test::Mojo.
- Added GET/POST parameter support to respond_to.
- Made class_to_file slightly smarter.
- Improved documentation.

1.85 2011-08-20 00:00:00
Expand Down
6 changes: 5 additions & 1 deletion lib/Mojo/Command.pm
Expand Up @@ -49,6 +49,7 @@ sub chmod_rel_file {
sub class_to_file {
my ($self, $class) = @_;
$class =~ s/:://g;
$class =~ s/([A-Z])([A-Z]*)/$1.lc($2)/gex;
decamelize $class;
return $class;
}
Expand Down Expand Up @@ -426,7 +427,10 @@ Portably change mode of a relative file.
Convert a class name to a file.
FooBar -> foo_bar
Foo::Bar -> foo_bar
FOO::Bar -> foobar
FooBar -> foo_bar
FOOBar -> foobar
=head2 C<class_to_path>
Expand Down
14 changes: 11 additions & 3 deletions t/mojo/command.t
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use Mojo::Base -strict;

use Test::More tests => 17;
use Test::More tests => 23;

use Cwd 'cwd';
use File::Spec;
Expand Down Expand Up @@ -39,8 +39,16 @@ is_deeply [sort keys %{$command->get_all_data('Example::Package::Windows')}],
[qw/template3 template4/], 'right DATA files';
close $data;

# Class to file and path
is $command->class_to_file('Foo::Bar'), 'foo_bar', 'right file';
# Class to file
is $command->class_to_file('Foo::Bar'), 'foo_bar', 'right file';
is $command->class_to_file('FooBar'), 'foo_bar', 'right file';
is $command->class_to_file('FOOBar'), 'foobar', 'right file';
is $command->class_to_file('FOOBAR'), 'foobar', 'right file';
is $command->class_to_file('FOO::Bar'), 'foobar', 'right file';
is $command->class_to_file('FooBAR'), 'foo_bar', 'right file';
is $command->class_to_file('Foo::BAR'), 'foo_bar', 'right file';

# Class to path
is $command->class_to_path('Foo::Bar'), 'Foo/Bar.pm', 'right path';

# Environment detection
Expand Down

0 comments on commit 89e14c4

Please sign in to comment.