Skip to content

Commit

Permalink
Merge pull request #179 from skaji/module-name
Browse files Browse the repository at this point in the history
respect hyphen in module names when mi6 new
  • Loading branch information
skaji authored Mar 27, 2024
2 parents 2fb79f6 + fab2331 commit 556ff24
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = App-Mi6
name = App::Mi6

[ReadmeFromPod]
filename = lib/App/Mi6.rakumod
Expand Down
20 changes: 12 additions & 8 deletions lib/App/Mi6.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ my $to-module = -> $file {
$normalize-path($file).subst('lib/', '').subst('/', '::', :g).subst(/$MODULE-EXT$/, '');
};
my $to-file = -> $module {
'lib/' ~ $module.subst(rx{ '::' | '-' }, '/', :g) ~ '.rakumod';
'lib/' ~ $module.subst('::', '/', :g) ~ '.rakumod';
};

my sub config($section, $key?, :$default = Any) {
Expand All @@ -56,7 +56,6 @@ method !cpan-user() {
}

multi method cmd('new', $module is copy, :$cpan) {
$module ~~ s:g/ '-' /::/;
my $main-dir = $module;
$main-dir ~~ s:g/ '::' /-/;
die "Already exists $main-dir" if $main-dir.IO ~~ :d;
Expand Down Expand Up @@ -406,12 +405,17 @@ method find-provides() {
sub guess-main-module() {
die "Must run in the top directory" unless "lib".IO ~~ :d;
if my $name = config("_", "name") {
my $file = $to-file($name).subst(".rakumod", "");
$file = "$file.pm6".IO.e ?? "$file.pm6"
!! "$file.pm".IO.e ?? "$file.pm"
!! "$file.rakumod".IO.e ?? "$file.rakumod"
!! "";
return ($to-module($file), $file) if $file;
my @file = <<rakumod pm6 pm>>.map(-> $ext {
|(
'lib/' ~ $name.subst('::', '/', :g) ~ ".$ext",
'lib/' ~ $name.subst(rx{ '-' | '::' }, '/', :g) ~ ".$ext",
);
});
for @file -> $file {
if $file.IO.e {
return ($to-module($file), $file);
}
}
}
my @module-files = mi6run("git", "ls-files", "lib", :out).out.lines(:close).grep(/$MODULE-EXT$/);
my $num = @module-files.elems;
Expand Down
4 changes: 2 additions & 2 deletions lib/App/Mi6/Template.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ our sub template(:$module, :$module-file, :$dist, :$author, :$auth, :$email, :$y
my %template =

Changes => qq:to/EOF/,
Revision history for $dist
Revision history for $module
\{\{\$NEXT\}\}
- Initial version
EOF

dist => qq:to/EOF/,
name = $dist
name = $module
[ReadmeFromPod]
filename = $module-file
Expand Down
4 changes: 2 additions & 2 deletions xt/01-actual.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ my $tempdir = tempdir;
my $meta = App::Mi6::JSON.decode( "META6.json".IO.slurp );
is $meta<description>, "blah blah blah";
is $meta<auth>, "zef:test-user";
"lib/Hello.pm6".IO.spurt: q:to/EOF/;
"lib/Hello.rakumod".IO.spurt: q:to/EOF/;
use v6;
unit module Hello;

Expand Down Expand Up @@ -81,7 +81,7 @@ my $tempdir = tempdir;
"lib/Hello/World4.pm6".IO.spurt("");
"lib/Hello/World5.pm6".IO.spurt("");
"dist.ini".IO.spurt: q:to/EOF/;
name = Hello-World
name = Hello::World
[PruneFiles]
filename = lib/Hello/World5.pm6
[MetaNoIndex]
Expand Down

0 comments on commit 556ff24

Please sign in to comment.