#!/usr/bin/env perl
use strict;
use warnings;
use FindBin::libs;
use CPAN::Packager::Script;
use Log::Log4perl qw(:easy);

my $level = $ENV{CPAN_PACKAGER_DEBUG} ? $DEBUG : $INFO;

my $layout = '%p: %m{chomp}%n'; #INFO Level
$layout = '%p %d{HH:mm:ss} [%c:%L]: %m{chomp}%n' if($level == $DEBUG);

Log::Log4perl->easy_init({ level => $level,
                           layout => $layout });

my $script = CPAN::Packager::Script->new_with_options;
$script->run;

__END__

=head1 NAME

cpan-packager -  create redhat/debian packages from perl modules

=head1 SYNOPSIS

case1: build a module

    sudo cpan-packager --module Test::Exception --builder Deb --conf conf/config.yaml --verbose

case2: build multiple modules at a time 

    sudo cpan-packager --modulelist modulelist.txt --builder RPM --conf conf/config.yaml --verbose

options
    --module         module name (required option)
    --builder        Deb or RPM (optional. default is Deb)
    --conf           configuration file path (required)
    --always-build   always build cpan modules if module is aready installed (optional)
    --modulelist     File containing a list of modules that should be built. (optional)
    --verbose        print command result (optional)

RPM/Deb Packages are generated at ~/.cpanpackager/{deb or rpm}

=head2 Configuration location and schema

config.yaml is located at github repo.

    See http://github.com/dann/p5-cpan-packager

Please see the configuration schema if you want to write config your self.
You can see schema like below.

    perldoc CPAN::Packager::Config::Schema


=head2 Configure CPAN mirrors

CPAN::Packager downloads modules from cpan_mirrors 
if you set CPAN mirror uri in your config.

    ---
    global:
      cpan_mirrors:
        - http://ftp.funet.fi/pub/languages/perl/CPAN/
        - file:///home/dann/minicpan

=head2 Use cpan-packager with minicpan

You can use minicpan with CPAN::Packager.
At first, you mirror CPAN modules with minicpan.

    minicpan -r http://ftp.funet.fi/pub/languages/perl/CPAN/ -l ~/minicpan

Set cpan mirrors uri in your config if you want to use minicpan.
after that you just use cpan-packager ;)

    ---
    global:
      cpan_mirrors:
        - file:///home/dann/minicpan

=head2 How to use the config (Advanced)

=head3 Fix broken MEATA.yml of some modules like:

  global:
    fix_meta_yml_modules:
      - YAML 
      - Class::Member
      - HTTP::Request::AsCGI

=head3 Apply patches to tarball when you build rpms

You need to write the configuration like:

  - module: Acme
    custom:
      tgz_path: ~/.cpanpackager/custom_module/Acme-1.11111.tar.gz
      patches: 
        - ~/.cpanpackager/custom_module/acme_test.patch
      dist_name: Acme
      version: 1.11111

The patch is like:

    --- Acme-1.11111/t/acme.t.orig	2010-01-26 22:26:51.000000000 +0900
    +++ Acme-1.11111/t/acme.t	2010-01-26 22:26:39.000000000 +0900
    @@ -1,8 +1,10 @@
     use lib 't', 'lib';
     use strict;
     use warnings;
    -use Test::More tests => 2;
    +use Test::More tests => 3;
     use Acme;
     
     ok(acme->is_acme);
     ok(acme->is_perfect);
    +ok 1;
    +
       

=head2 Specify installation location (optional)

It is possible for a CPAN::Packager user to explicitly specify 
installation locations for a distribution's
libraries, documentation, man pages, binaries, and scripts. Setting
both of the below environment variables, for example, will accomplish
this.

    PERL_MM_OPT="INSTALLVENDORMAN1DIR=/usr/local/share/man/man1
    INSTALLVENDORMAN3DIR=/usr/local/share/man/man3
    INSTALLVENDORBIN=/usr/local/bin INSTALLVENDORSCRIPT=/usr/local/bin"

    PERL_MB_OPT="--config installvendorman1dir=/usr/local/share/man/man1
    --config installvendorman3dir=/usr/local/share/man/man3 --config
    installvendorbin=/usr/local/bin --config
    installvendorscript=/usr/local/bin"

Additionally, for RPMs, you may specify the directory in which non-man
documentation (Changes, README, etc) are installed via adding an entry
to your ~/.rpmmacros file:

%_defaultdocdir /usr/local/share/doc

=head2 Additional setup (For debian users)

Copy conf/debian/rules* to ~/.dh-make-perl directory.
copying perllocal.pod is conflited  if you dont do that. 

=head1 ENVIRONMENT VARIABLES

Environment variable C<CPAN_PACKAGER_TEST_LIVE> can be used to execute live
tests. 

Environment variable C<CPAN_PACKAGER_ENABLE_DUMP> can be used to dump
variables.

=head1 DESCRIPTION

cpan-packager will create the files required to build a debian or redhat source 
package out of a perl package. This works for most simple packages and is also 
useful for getting started with packaging perl modules. Given a perl package name, 
it can also automatically download it from CPAN. 

=head1 BUGS

Please report any bugs or feature requests to "<bug-CPAN-Packagerat rt.cpan.org>", or through
the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPAN-Packager>.  I will be
notified, and then you’ll automatically be notified of progress on your bug as I make changes.

=head1 AUTHOR

Takatoshi Kitano E<lt>kitano.tk@gmail.comE<gt>

=head1 LICENSE

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

=cut
