Everytime you create a new file in your project you need to type the package name:
lib/My/Project/DB/Result/Person.pm => My::Project::DB::Result::Person
That's really annoying, boring and prone to error. For Textmate users there's a simple solution (notice: the script expects your modules in directory "lib"):
Save that script and setup a new command in Textmates bundle editor as shown in the screenshot:
Next time you create a new perl module just hit Cmd + Ctrl + p and select "Filename to Package":
If the file is empty the script will insert following code:
lib/My/Project/DB/Result/Person.pm => My::Project::DB::Result::Person
That's really annoying, boring and prone to error. For Textmate users there's a simple solution (notice: the script expects your modules in directory "lib"):
#!/usr/bin/env perl
use strict;
use warnings;
my $package = get_package( path => $ENV{TM_FILEPATH}, walk_up_to => 'lib' );
my $content = get_content();
if ($content) {
$content =~ s/^package (.*?);/package $package;/;
print $content;
}
else {
print "package $package;\n\nuse strict;\nuse warnings;\n\n1;";
}
sub get_content {
local $/ = undef;
return <>;
}
sub get_package {
my (%args) = @_;
my @chunks = split qr~/~, $args{path};
while ( @chunks > 0 ) {
last if $chunks[0] eq $args{walk_up_to};
shift @chunks;
}
shift @chunks;
my $pkg = join '::', @chunks;
$pkg =~ s/\.pm//g;
return $pkg;
}
Save that script and setup a new command in Textmates bundle editor as shown in the screenshot:
Next time you create a new perl module just hit Cmd + Ctrl + p and select "Filename to Package":
If the file is empty the script will insert following code:
package My::Project::DB::Result::Person; use strict; use warnings; 1;If the file contained code already the script will just update the "package ...;" line with the new value. This is very handy if you move a file around and just want to update the package name.
