Using Dist::Zilla to extract parts of your distribution

Imagine you are working on a smallish Catalyst project with an DBIx::Class model. You have been a good citizen and adhered to the principal of separation of concerns. Now you would like to extract the schema to use it anywhere else (in my case a monitoring interface that is in place and allows simple plugins). Creating a whole distribution with the related infrastructure out of the schema classes is just to much work for this one-off task. Dist::Zilla to the rescue.

Dist::Zilla can't handle multiple dists in one directory, so you have to create an empty subdir in the project. I'll go with contrib/schema for now. Put the following

name    = MyApp-Schema
author  = You <>
license = None
copyright_holder = You
copyright_year   = 2011
version = 0.01
main_module = lib/MyApp/


DBIx::Class = 0
DBD::SQLite = 0
Test::DBIx::Class = 0

root   = ../../lib/MyApp/Schema
prefix = lib/MyApp/Schema

; this is a hack to additionally gather the schema class
; maybe there is a better way, but I was not able to
; find a plugin that can gather files and also support
; a GatherDir-like prefix option
[GatherDir / Schema]
root   = ../../lib/MyApp/
prefix = lib/MyApp/
exclude_match = (?<!$

[GatherDir / Tests]
root   = ../../t/schema
prefix = t/schema
Rendered by emacs, blooper.el and htmlize.el

Now change to the directory and run

dzil build
Rendered by emacs, blooper.el and htmlize.el

and you should have a shiny MyApp-Schema-0.01.tar.gz at your (not really best practice) disposal.

Leave a comment

About Sebastian Willert

user-pic Programming Perl 5 in Emacs for over a decade, blogging since a few minutes. Expect tidbits about both technologies here (if at all, I'm not too sure I can develop a blogging habit).