5 tips for writing better Perl6 modules

1. Provide a provides section

Without giving a provides section in your META file, a package manager will just have to recursively grep your directories and hope that anything it happens to find is actually part of the package. Yuck. Instead we should be explicit about what our package provides:

# META6.json
"provides" : { 
    "Module"            => "lib/Module.pm6", 
    "Module::Submodule" => "lib/Module/Submodule.pm6"
}

Make sure you use the correct extension (.pm or .pm6), and use relative paths.

2. Don't miss those test and build dependencies.

Be sure to thoroughly test your module, not just in the same dev enviroment you always use. Look at any build or test files and make sure any external dependencies are listed under build-depends and test-depends in your META file. Uninstall/delete your installed modules and try to build/test/install froms scratch if you must. Does it still work? Good. Now test it with --ll-exception. Did it suddenly fail? If so, thats because without --ll-exception missing dependencies in a test still exit 0, resulting in tests passing.

# META6.json
"build-depends" : [ "LibraryMake" ]

Using a Build.pm? If you are actually using functionality from Panda::Builder then you probably need to add panda to your depends. If you are not using any of the functionality from it you can drop the dependency by using this template:

class Build {
    method build($where) { ... }

    # work around needless dependency
    method isa($what) {
        return True if $what.^name eq 'Panda::Builder';
        callsame;
    }    
}
3. Write tests.

Please! Why would you submit a module to the ecosystem without any tests? Go open your README, copy the example or synopsis, and make it a test already!

4. Resist the "boilerplate-only module ecosystem submission" urge

It can be frustrating for newcomers to have to wade through empty shells of boilerplate. The intentions behind such submissions are undoubtedly good, but consider waiting until your module does something (even if its fail its own tests). The namespace isn't going anywhere... if someone else "takes" it that doesn't mean you can't still use it yourself. use MyModule:auth<github:ugexe>.

5. Take note of errors found by Perl6 smoke testers

Maybe you don't have a Windows or OSX machine to test your module on, but intend for it to work on multiple platforms. The Perl6 smoke reports, found at http://testers.perl6.org/recent.html, can be helpful for finding errors run by other people on different configurations.