# PODNAME: App::CharmKit::Manual::GettingStarted
# ABSTRACT: Getting started with CharmKit

__END__

=pod

=encoding UTF-8

=head1 NAME

App::CharmKit::Manual::GettingStarted - Getting started with CharmKit

=head1 VERSION

version 0.011

=head1 Getting Started

=head2 Creating a project

All development happens within B<src/> and the builtin C<pack> command
is used for generating the proper hooks/tests and dependencies within that
directory so Juju is able to act upon them. Hooks within B<hooks/> directory
are always overwritten, think of this similar to a B<dist> or B<release> directory.

To start a project:

  $ charmkit init [--with-hooks] <charm-name>

If used C<--with-hooks> then B<src/hooks/> will be populated with all the default
hooks. A few questions will be prompted and then the project is generated with
F<charmkit.json>, F<config.yaml>, F<metadata.yaml>, F<LICENSE>, F<README.md>,
and F<Makefile>.

=head2 Directory Layout

Once a project is created the structure of your project should look similar to:

  charm-project/
    hooks/
      install
      config-changed
      start
      stop
    src/
      hooks/
        install
        config-changed
        start
        stop
      tests/
        00-basic.test
    tests/
      00-basic.test
    config.yaml
    metadata.yaml
    LICENSE
    README.md
    charmkit.json
    Makefile

=head2 Creating hooks

By default CharmKit allows the creation of a set of default unit hooks.
Those hooks are B<install>, B<config-changed>, B<start>, B<upgrade-charm>, B<stop>.

  $ charmkit generate upgrade-charm

Or you can generate all known default unit hooks:

  $ charmkit generate -a

A special relation hook can be created with the C<-r> option:

  $ charmkit generate -r database-relation-joined

=head2 Writing charm hooks

Hooks are written using perl with automatically imported helpers for convenience.
When developing hooks they should reside in B<src/hooks>.

A typical hook starts with

   #!/usr/bin/env perl

   use charm;

   log 'Starting install hook for database';

   apt_install(['mysql-server', 'nginx', 'php5-fpm'])

   my $dbhost = relation_get 'dbhost';
   my $dbuser = relation_get 'dbuser';

   service_control('nginx', 'restart');

=head2 Writing charm tests

Tests are written in the same way and should live in B<src/tests/*.test>.

A typical test starts with

   #!/usr/bin/env perl

   use charm -tester;

   # See if an nginx config file exists
   ok (-e '/etc/nginx/sites-enabled/mysite.com', 'found nginx site config');

   my $ret = service_status('nginx');
   ok ($ret->{error} eq 0, 'nginx is running);

   # finish tests
   done_testing;

Tests are built in a way that the test runner from the charm reviewers will be
able to run and validate your charm. The tests can be executed calling them directly
(how the test runner does it) or running with:

   $ charmkit test

or

   $ prove -lv tests/*.test

=head2 Packaging a charm for release

Once development is complete and you have your hooks defined and tests written.
Packaging a charm for release to either Git or the Charm Store is a matter of
running:

  $ charmkit pack

=head2 Getting external charms

CharmKit currently only supports cloning from GitHub.

  $ charmkit get battlemidget/test-charm

=head1 AUTHOR

Adam Stokes <adamjs@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Adam Stokes.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=head1 DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

=cut
