in reply to Re: Adding a class to a module - Can Module::Starter or Dist::Zilla help?
in thread Adding a class to a module - Can Module::Starter or Dist::Zilla help?

Thank you, i will try and use Module::Starter::Plugin or its Template API. The POD documentation is quite short, i'll try and tweak it around.

I will try and use Module::Starter::Smart again, right now, and comment what i'm doing (on a Windows XP OS).

First of all, here is my C:/Dropbox/.module-starter/config file :

author: mascip email: example@gmail.com builder: Module::Build plugin: Module::Starter::Smart plugins: Module::Starter::PBP template_dir: C:\Dropbox\.module-starter\PBP

If you think that not using the PBP plugin, i could just take it off the configuration file, and do all of this again.

Now, i use module-starter

C:\>module-starter --distro=My-Example --module=My::Example::Class --m +odule=Other::Example configdir : C:\Dropbox\.module-starter configdir : C:\Dropbox\.module-starter Added to MANIFEST: Build.PL Added to MANIFEST: Changes Added to MANIFEST: ignore.txt Added to MANIFEST: lib/My/Example/Class.pm Added to MANIFEST: lib/Other/Example.pm Added to MANIFEST: MANIFEST Added to MANIFEST: README Added to MANIFEST: t/00.load.t Added to MANIFEST: t/perlcritic.t Added to MANIFEST: t/pod-coverage.t Added to MANIFEST: t/pod.t Created starter directories and files
Now my distro is created, and i check in the C:/My-Example/My/Example/Class.pm file that the boilerplate is as expected. It is. In the code i can read
=head1 AUTHOR mascip C<< <example@gmail.com> >
which shows that my configuration file did its job (i changed the email address to example@gmail.com, just before starting this example).

Now it's time to try and use Module::Starter::Smart, which was included in the configuration file as you can see above.

C:\>module-starter --distro=My-Example --module=My::Example::TheNewCla +ss configdir : C:\Dropbox\.module-starter configdir : C:\Dropbox\.module-starter My-Example already exists. Use --force if you want to stomp on it.
It doesn't work as expected.

Now i try it the other way around, giving the --module argument before --ditro, and obtain the same result :

C:\>module-starter --distro=My-Example --module=My::Example::TheNewCla +ss configdir : C:\Dropbox\.module-starter configdir : C:\Dropbox\.module-starter My-Example already exists. Use --force if you want to stomp on it.

And finally, if i go in my distro's directory, and try to create a module, then a get a whole new distro inside my first distro:

C:\>module-starter --distro=My-Example --module=My::Example::TheNewCla +ss configdir : C:\Dropbox\.module-starter configdir : C:\Dropbox\.module-starter My-Example already exists. Use --force if you want to stomp on it.

Did i do anything wrong?

Replies are listed 'Best First'.
Re^3: Adding a class to a module - Can Module::Starter or Dist::Zilla help?
by kcott (Archbishop) on Aug 13, 2012 at 15:09 UTC

    Nothing you have here leaps out at me as being wrong.

    I had a dig around in some of the source code. Module::Starter::PBP inherits from Module::Starter::Simple. It is Module::Starter::Simple's create_basedir() method that generates the "... already exists.  Use --force if you want to stomp on it." message. As far as I can see, you can't use Module::Starter::PBP to add a module to an existing distribution - I'm happy to be contradicted on that if someone knows a way to do it.

    None of the examples in my original reply used Module::Starter::PBP. You may find excluding that plugin fixes the immediate problem but I wouldn't really consider that a particularly good solution. You could subclass Module::Starter::PBP and write your own create_basedir() method - that's just a suggestion, there may be other implications which you should look into first.

    -- Ken

      Thank you for feedback. I've tried without the PBP plugin and templates, and it did the same anyway.

      I just peeked in the Module::Starter::Smart source code, to find the same thing as you, the error message comes from create_basedir().

      The documentation says:
      "When invoked, the plugin checks if the distribution is already created. If so, the plugin would bypass C<create_basedir>) and go ahead pull in all the existing modules and test files; these information would be used later in the corresponding file creation subroutines for skipping already-created files"

      So, it means that the create_distro() function doesn't do its job : it should not call create_basedir(), when the C:/My-Example already exists.

      * Tweaking-searching in the modules... *

      Ah !!! Here you go, i found the problem ! By adding print() statements both in Module/Starter/Simple.pm and Module/Starter/Smart.pm, i realized that when i use module-starter, it's Module::Starter::Simple who runs, not Module::Starter::Smart

      If anybody knew why, it'd be good to hear. Otherwise, i'll have to try and understand how Module::Starter::Simple checks for plugin in the configuration file, and then uses them. I'll see if-when i have the time.

      At least, part of the mystery is solved.

      Edit-bis : my last Edit was wrong.

        I found that i could use the --plugin=Module::Starter::Smart argument, to use the plugin. Now it works properly.

        I still don't know why the configuration line's plugin: Module::Starter::Smart didn't work previously. While all the others worked properly.

        Edit: Well, i get it now. I can use one plugin or the other, but not both, as they inherit from the same class (Module::Starter::Simple). So, Module::Starter::PBP and Module::Starter::Smart won't work simultaneously.
        Well... They will, if i cheat. I just changed Module/Starter/Smart.pm, so that it inherits from Module::Starter::PBP, instead of Module::Starter::Simple. It works !

        Is there any way to make a cleaner solution, from this dirty one?