[Catalyst] Catalyst::Helper - author details

Chisel Wright chisel at herlpacker.co.uk
Wed Dec 7 20:53:38 CET 2005


Since reading PBP I've started using Module::Starter(::PBP) to create
new perl modules. I expect that a few other people may be doing this
too.

Setting it up to be automatic for some details means there's another
handy source of author information.

Since Catalyst::Helper is currently getting my details from /etc/passwd,
I'm being credited as "Chisel Wright,,," or ",,," depending on the
machine I'm using.

This got me to thinking; why not use the module-starter information (if
it exists). Slot it in after $ENV{AUTHOR} so it can always be
overridden, but before using /etc/passwd, so I don't get ",,," as my
name.

So, on that thought I knocked up a patch which I believe does exactly
that. If you think it's useful/worthwhile I'd love to see it added to
trunk/
The patch should run from catalyst/trunk/Catalyst/ I think.

Chisel
-- 
Chisel Wright
e: chisel at herlpacker.co.uk
w: http://www.herlpacker.co.uk/

No virus was found in this outgoing message as I didn't bother looking.
-------------- next part --------------
--- lib/Catalyst/Helper.pm	2005-11-23 20:38:51.000000000 +0000
+++ lib/Catalyst/Helper.pm.new	2005-12-07 18:22:42.000000000 +0000
@@ -72,6 +72,7 @@
     $self->{startperl} = '#!/usr/bin/perl -w';
     $self->{scriptgen} = $Catalyst::CATALYST_SCRIPT_GEN || 4;
     $self->{author}    = $self->{author} = $ENV{'AUTHOR'}
+      || module_starter_author()
       || eval { @{ [ getpwuid($<) ] }[6] }
       || 'Catalyst developer';
 
@@ -263,6 +264,44 @@
     return File::Spec->catfile( $dir, "$type\_$tname" );
 }
 
+=head3 module_starter_author
+
+Try to deduce the author name from a L<Module::Starter> config file
+
+=cut
+sub module_starter_author {
+    my ($self) = @_;
+    my ($configdir, $configfile, $author, %config);
+
+    # get the module-starter config file
+    $configdir = $ENV{MODULE_STARTER_DIR}
+        || ($ENV{HOME} ? $ENV{HOME} . '/.module-starter' : '');
+    $configfile = "${configdir}/config";
+
+    # if we don't have it, don't use it
+    return unless -e $configfile;
+
+    # read the config file
+    open my $config_file, '<', $configfile
+      or die "couldn't open config file $configfile: $!";
+    while (<$config_file>) {
+        chomp;
+        next if /\A\s*\Z/sm;
+        if (/\A(\w+):\s*(.+)\Z/sm) { $config{$1} = $2; }
+    }
+
+    # abort if we don't know who the author is
+    return unless defined $config{author};
+
+    # build the author string
+     $author = $config{author};
+    # add an email address if we have one
+    if ($config{email}) {
+        $author = "$author C<< <$config{email}> >>";
+    }
+    return $author;
+}
+
 =head3 render_file
 
 Render and create a file from a template in DATA using 
@@ -465,6 +504,8 @@
 
 Sebastian Riedel, C<sri at oook.de>
 
+Chisel Wright, C<pause at herlpacker.co.uk>
+
 =head1 LICENSE
 
 This library is free software, you can redistribute it and/or modify


More information about the Catalyst mailing list