Skip to content

Commit

Permalink
Fix: do not camelize class name with no #
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrtj committed Jun 27, 2024
1 parent a3faae8 commit f858d52
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ Revision history for Kelp

{NEXT}
[New Interface]
- Kelp::Base no longer imports namespace::autoclean with -strict
- Kelp::Base can now be imported with -attr

[Changes]
- Kelp::Base no longer imports namespace::autoclean with -strict
- Fixed camelizing of controller names if they don't contain a hash sign

2.12 - 2024-06-26
[Changes]
- Kelp::Exception->throw now also works on objects (rethrows an exception)
Expand Down
2 changes: 1 addition & 1 deletion lib/Kelp/Manual/Controllers.pod
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ C<context> tracking object:

# get a temporary rebless of the app and call its bulid method
# will return MyApp::Controller::Special, if route base is MyApp::Controller
my $controller_special = $self->context->controller('special');
my $controller_special = $self->context->controller('Special');
$controller_special->build;

# will return the main controller (MyApp::Controller)
Expand Down
7 changes: 6 additions & 1 deletion lib/Kelp/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ sub camelize
$base = undef if $sigil;

my @parts;
if ($string =~ /::/) {
if ($string !~ /#/) {

# do not camelize if it doesn't look like a camelize string
@parts = ($string);
}
else {
Expand Down Expand Up @@ -228,6 +230,9 @@ The returned string will have leading C<+> removed and will be prepended with
the second argument if there was no C<+>. An optional third argument can also
be passed to treat the entire string as a class name.
Will not do the camelizing if there is no C<#> sign in the string, even if
the third argument is present.
=head2 extract_class
Extracts the class name from a C<Controller::action> string. Returns undef if
Expand Down
2 changes: 1 addition & 1 deletion t/lib/MyApp2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sub build
$r->add("/test_res_template", "bar#test_res_template");

$self->context->controller->build;
$self->context->controller('bar')->build;
$self->context->controller('Bar')->build;
}

1;
Expand Down
4 changes: 2 additions & 2 deletions t/util.t
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ subtest 'testing camelize (class only)' => sub {
'BarFoo#baz' => 'Barfoo::Baz',
'barfoo#BAZ' => 'Barfoo::Baz',
'bar_foo_baz_bat#moo_moo' => 'BarFooBazBat::MooMoo',
'a' => 'A',
'a' => 'a',
'M::D::f' => 'M::D::f',
'R_E_S_T#asured' => 'REST::Asured',
'REST::Assured::ok' => 'REST::Assured::ok',
'REST' => 'Rest',
'REST' => 'REST',
);

for my $k (keys %h) {
Expand Down

0 comments on commit f858d52

Please sign in to comment.