Mailing List Archive

[PATCH] preserve $self->{name} in mk_app if defined
previously you could create a new helper object with name already defined but
when you ran mk_app you had to pass a name parameter which would overwrite the
potentially already defined name. This patch allows you to do either, however
a name defined at the creation of a new helper object will take precedence.

Signed-off-by: Caleb Cushing <xenoterracide@gmail.com>
---
this patch is based on Catalyst::Devel master. not sure what the workflow for
git repo's are so I'm just going buy git.git's workflow.

I haven't created a test yet for both functionalities or to verify what
happens in the event both are used. Is it necessary? this patch updates the
test to use the new syntax.

before you could do this

my $helper = Catalyst::Helper->new({
name => $name,
... ,
});
$helper->mk_app;

and name would get clobbered so you'd have to do

$helper->mk_app("$name");

in order to make it work. this seems silly if you are passing parameters to
new already. Now this:

my $helper = Catalyst::Helper->new({
name => $name,
});
$helper->mk_app;

and this:

my $helper = Catalyst::Helper->new;
$helper->mk_app("$name");

should work. Obviously the first is probably only preferred if you are passing
more than one parameter.

Also this new behavior is more in line with existing documentation which does
not mention a parameter being passed to mk_app.

lib/Catalyst/Helper.pm | 14 +++++++++-----
t/generated_app.t | 2 +-
2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm
index 3b182ad..705478e 100644
--- a/lib/Catalyst/Helper.pm
+++ b/lib/Catalyst/Helper.pm
@@ -78,16 +78,20 @@ sub mk_app {
# Needs to be here for PAR
require Catalyst;

- if ( $name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) {
+ $self->{name} = $name unless $self->{name};
+
+ if ( $self->{name} =~ /[^\w:]/
+ || $self->{name} =~ /^\d/
+ || $self->{name} =~ /\b:\b|:{3,}/
+ ) {
warn "Error: Invalid application name.\n";
return 0;
}
- $self->{name } = $name;
- $self->{dir } = $name;
+ $self->{dir } = $self->{name};
$self->{dir } =~ s/\:\:/-/g;
$self->{script } = dir( $self->{dir}, 'script' );
- $self->{appprefix } = Catalyst::Utils::appprefix($name);
- $self->{appenv } = Catalyst::Utils::class2env($name);
+ $self->{appprefix } = Catalyst::Utils::appprefix($self->{name});
+ $self->{appenv } = Catalyst::Utils::class2env($self->{name});
$self->{startperl } = -r '/usr/bin/env'
? '#!/usr/bin/env perl'
: "#!$Config{perlpath}";
diff --git a/t/generated_app.t b/t/generated_app.t
index 51cb3f1..55b60a2 100644
--- a/t/generated_app.t
+++ b/t/generated_app.t
@@ -37,7 +37,7 @@ chdir $dir or die "Cannot chdir to $dir: $!";
}
);

- $helper->mk_app('TestApp');
+ $helper->mk_app;
}

my $app_dir = File::Spec->catdir($dir, 'TestApp');
--
1.7.1.1


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev