Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dist::Zilla::Plugins:: Best Practices

Dist::Zilla::Plugins:: Best Practices

You've already written your own Dist::Zilla plugin (or you plan to write one)? Your dzil build are slow and you want to know why? This is for you.

In this talk I will expose a few tips that will help you to avoid adding more bloat to Dist::Zilla:
- how to discover performance issues (tools...)
- how to write efficient InlineFiles-based Test:: plugin
- best pratices to inject dependencies

Olivier Mengué

August 22, 2014
Tweet

More Decks by Olivier Mengué

Other Decks in Programming

Transcript

  1. Olivier Mengué DOLMEN - @omengue • IoT software engineer at

    IJENKO • Perl embeded in a gateway between a Home Area Network (HAN) and the Internet ; ZigBee, M-Bus, EnOcean… • Member of the Perl Toolchain Gang • Open Source: – 20+ dists on CPAN – 300+ tickets filled on rt.cpan.org ; – Maintainer of LiquidPrompt github:nojhan/liquidprompt – Personal projects : github-keygen, angel-PS1 – 72 commits in Dist::Zilla core (committer #3)
  2. Dist::Zilla plugins • Dist::Zilla::Plugin::* – Plugins referenced from dist.ini –

    Methods called during « phases » – dist.ini: [Name] • Dist::Zilla::Plugin::Test::* – Plugins that inject files test scripts in t/ or xt/ • Dist::Zilla::PluginBundle::* – Group of plugins, with settings, packaged – dist.ini: [@Name] • Dist::Zilla::App::Command::* – For dzil sub commands
  3. dzil performance : profiling • List modules loaded by dzil

    perl ­d:TraceUse=output:out.txt ­S dzil nop • Check dzil run flamegraph to find major hot spots perl ­d:NYTProf ­S dzil listdeps nytprofhtml ­­open
  4. ?? POLL ?? How many modules are loaded by dzil

    nop for [@Milla] Dist::Milla is bundle that provides a useful set of plugins. Reply is system dependent as it depends on plugins installed.
  5. 543

  6. Solution: lazy loading Replace... with... use Foo::Bar; sub foo {

    my $foo = Foo::Bar­>new; } sub foo { require Foo::Bar; my $foo = Foo::Bar­>new; } use Foo::Bar qw< bar >; sub foo { bar(…); } sub foo { require Foo::Bar; Foo::Bar::bar(…); }
  7. Dist::Zilla::App::Command::* • All plugins are loaded every time you run

    'dzil', whatever the command • Impacts all builds of all your projects • Fix : delay loading of dependencies to the execute method
  8. Dist::Zilla::Plugin::* • Use your plugin for the build of the

    distribution of the plugin – Eat your own dog food – Find issues early – Just building the dist is one more test! • How to: – Use the plugin in dist.ini – But use [Bootstrap::lib] before else you use the last installed one in @INC, not the one in development
  9. Dist::Zilla::Plugin::Test::* • If the generated script uses a module, inject

    the module as a prereq so it appears in dzil listdeps ­­author – Author, release tests must inject as 'develop' prereq – Others tests as 'test' prereq • The test script must fail (loudly) if the prereq is missing – « Soft failure » (skip the test if prereq missing) is a failure of the plugin author as that makes the plugin useless • How to: – Use Dist::Zilla::Role::PrereqSource – Example: Dist::Zilla::Plugin::Test::NoTabs
  10. Dist::Zilla::PluginBundle::* • Eat your own dog food … after [Bootstrap::lib]

    • Use Dist::Zilla::Role::PluginBundle::PluginRemover – Convenient for users of the bundle
  11. Summary • As a dzil user, profile your own builds,

    report issues to plugin authors • As a plugin author, delay dependency loading
  12. Questions? [email protected] Twitter: @omengue IRC: dolmen in #distzilla Slides :

    not yet on... http://o.mengue.free.fr/presentations/ Https://speakerdeck.com/dolmen