File Coverage

blib/lib/EPublisher.pm
Criterion Covered Total %
statement 68 75 90.6
branch 20 30 66.6
condition 15 21 71.4
subroutine 12 13 92.3
pod 5 5 100.0
total 120 144 83.3


line stmt bran cond sub pod time code
1             package EPublisher;
2              
3             # ABSTRACT: Publish documents in new format
4              
5 6     6   2776 use strict;
  6         14  
  6         180  
6 6     6   33 use warnings;
  6         12  
  6         156  
7 6     6   27 use Carp;
  6         11  
  6         319  
8              
9 6     6   2536 use EPublisher::Config;
  6         15  
  6         191  
10 6     6   2487 use EPublisher::Source;
  6         17  
  6         168  
11 6     6   1832 use EPublisher::Target;
  6         14  
  6         4305  
12              
13             our $VERSION = 1.25;
14              
15             sub new{
16 6     6 1 4389 my ($class,%args) = @_;
17 6         16 my $self = bless {}, $class;
18            
19 6 100       27 $self->config( $args{config} ) if exists $args{config};
20 6         24 $self->_debug( $args{debug} );
21            
22 6         19 return $self;
23             }
24              
25             sub config{
26 11     11 1 396 my ($self,$data) = @_;
27            
28 11         21 my $ref = ref $data;
29 11 100 100     54 if( defined $data and !$ref ){
    100 66        
30 2         5 $self->{_configfile} = $data;
31 2         6 $self->_config(1);
32             }
33             elsif ( $ref and $ref eq 'HASH' ) {
34 1         3 $self->_config( 1, $data );
35             }
36            
37 11         46 return $self->{_configfile};
38             }
39              
40             sub projects {
41 0     0 1 0 my ($self) = @_;
42            
43 0         0 my $config = $self->_config;
44            
45 0 0       0 return if !$config;
46 0 0       0 return if !ref $config;
47 0 0       0 return if ref $config ne 'HASH';
48            
49 0         0 return keys %{$config};
  0         0  
50             }
51              
52             sub run{
53 3     3 1 394 my ($self,$projects) = @_;
54              
55             PROJECT:
56 3         9 for my $project ( @$projects ){
57 3         6 my $config = $self->_config->{$project};
58            
59 3 50       10 next PROJECT if !$config;
60            
61             # load the source
62 3         6 my $sources = $config->{source};
63 3 50 33     20 $sources = [ $sources ] if !ref $sources or ref $sources ne 'ARRAY';
64            
65 3         5 my @pods;
66 3         7 for my $source ( @{$sources} ) {
  3         6  
67 3 50       43 die('No type in source.') unless (exists $source->{type});
68 3         13 $self->debug('100: ' . $source->{type} );
69 3         19 my $source_obj = EPublisher::Source->new( $source );
70 3         12 $source_obj->publisher( $self );
71            
72 3         19 my @pod_source = $source_obj->load_source;
73 3 50 33     44 @pod_source = ({ pod => '', title => '', filename => '' }) if !@pod_source || !$pod_source[0];
74            
75 3         10 $self->debug('101: ' . substr join( "", map{ $_->{pod} }@pod_source ), 0, 50 );
  3         28  
76            
77 3         42 push @pods, @pod_source;
78             }
79            
80 3         14 $config->{target}->{source} = \@pods;
81            
82             # deploy the project
83 3         16 $self->debug('200: ' . $config->{target}->{type} );
84 3         24 my $target = EPublisher::Target->new( $config->{target} );
85 3         19 $target->publisher( $self );
86 3         12 $target->deploy;
87             }
88             }
89              
90             sub _debug{
91 6     6   27 my ($self,$ref) = @_;
92            
93 6 100 66     42 if( @_ == 2 and ref($ref) eq 'CODE' ){
94 1         4 $self->{__debug} = $ref;
95 1         2 $self->{DEBUG} = 1;
96             }
97              
98 6         17 return $self->{__debug};
99             }
100              
101             sub debug {
102 9     9 1 23 my ($self,$message) = @_;
103            
104 9 100       25 return if !$self->{DEBUG};
105 3         8 $self->{__debug}->($message);
106             }
107              
108             sub _config{
109 11     11   1730 my ($self,$bool,$data) = @_;
110            
111 11 100 100     77 if ( $bool and $data ) {
    100 100        
112 1         4 $self->{__config} = $data;
113             }
114             elsif( !$self->{__config} or $bool ){
115 4 100       12 unless( $self->config ){
116 1         174 croak "no config file given!";
117             }
118 3         10 $self->{__config} = EPublisher::Config->get_config( $self->config );
119             }
120              
121 10         27 return $self->{__config};
122             }
123              
124             1;
125              
126             __END__