Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by kcott (Archbishop)
on Aug 12, 2012 at 08:43 UTC ( [id://986943]=note: print w/replies, xml ) Need Help??


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

"But when i try to use it in Windows XP, it seems to not understand that it should just add a module to the distro. It creates a new distro instead. I might not have set it up correctly ..."

Please show your .module-starter/config file and the full command you used. Without this, we can't tell if the setup is correct or if you used it correctly. For instance, modules have colons (e.g. --module=Some::Class) whereas distros have a hyphen (e.g. --distro=Some-Class) - perhaps those got mixed up on your commandline.

While I appreciate that your question specifically asks about "adding to an existing module", I'll just point out that you can create multiple modules in a single distribution without using any plugins, e.g.

module-starter --module=My::Example,My::Example::Class --distro=My-Exa +mple

Using the plugin Module::Starter::Smart, I can run

module-starter --module=My::Example

My::Example has boilerplate with author and email (from config). I added a little POD text (to later check this wasn't being overwritten) and ran

module-starter --module=My::Example::Class --distro=My-Example

My::Example was not overwritten and My::Example::Class has boilerplate with author and email (from config).

This appears to cover your "... have all folders and files created, as well as the boilerplates adapted." requirement.

For your specific customisations (e.g. logger code), perhaps consider writing your own plugin. You may find Module::Starter::Plugin and Module::Starter::Plugin::Template to be useful if you choose to do this. Taking a look at the source of existing plugins (e.g. Module::Starter::Smart and Module::Starter::PBP) may also be helpful.

I noticed that Module::Starter::Smart has:

UPDATE: This plugin only covers the simplest use cases. For advanced usage, check out Module::Starter::AddModule.

I'm not familiar with that module - it may be of use to you.

-- Ken

Replies are listed 'Best First'.
Re^2: Adding a class to a module - Can Module::Starter or Dist::Zilla help?
by Anonymous Monk on Aug 12, 2012 at 09:31 UTC
Re^2: Adding a class to a module - Can Module::Starter or Dist::Zilla help?
by mascip (Pilgrim) on Aug 13, 2012 at 09:30 UTC

    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?

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://986943]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-18 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found