| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package EPublisher; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # ABSTRACT: Publish documents in new format | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 6 |  |  | 6 |  | 2890 | use strict; | 
|  | 6 |  |  |  |  | 14 |  | 
|  | 6 |  |  |  |  | 172 |  | 
| 6 | 6 |  |  | 6 |  | 32 | use warnings; | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 151 |  | 
| 7 | 6 |  |  | 6 |  | 32 | use Carp; | 
|  | 6 |  |  |  |  | 13 |  | 
|  | 6 |  |  |  |  | 329 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 6 |  |  | 6 |  | 2485 | use EPublisher::Config; | 
|  | 6 |  |  |  |  | 14 |  | 
|  | 6 |  |  |  |  | 183 |  | 
| 10 | 6 |  |  | 6 |  | 2370 | use EPublisher::Source; | 
|  | 6 |  |  |  |  | 14 |  | 
|  | 6 |  |  |  |  | 173 |  | 
| 11 | 6 |  |  | 6 |  | 1960 | use EPublisher::Target; | 
|  | 6 |  |  |  |  | 15 |  | 
|  | 6 |  |  |  |  | 4548 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $VERSION = 1.26; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub new{ | 
| 16 | 6 |  |  | 6 | 1 | 4693 | my ($class,%args) = @_; | 
| 17 | 6 |  |  |  |  | 16 | my $self = bless {}, $class; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 6 | 100 |  |  |  | 31 | $self->config( $args{config} ) if exists $args{config}; | 
| 20 | 6 |  |  |  |  | 27 | $self->_debug( $args{debug} ); | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 6 |  |  |  |  | 22 | return $self; | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub config{ | 
| 26 | 11 |  |  | 11 | 1 | 409 | my ($self,$data) = @_; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 11 |  |  |  |  | 28 | my $ref = ref $data; | 
| 29 | 11 | 100 | 100 |  |  | 58 | if( defined $data and !$ref ){ | 
|  |  | 100 | 66 |  |  |  |  | 
| 30 | 2 |  |  |  |  | 7 | $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 |  |  |  |  | 55 | 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 | 390 | my ($self,$projects) = @_; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | PROJECT: | 
| 56 | 3 |  |  |  |  | 9 | for my $project ( @$projects ){ | 
| 57 | 3 |  |  |  |  | 17 | my $config   = $self->_config->{$project}; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 3 | 50 |  |  |  | 14 | next PROJECT if !$config; | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | # load the source | 
| 62 | 3 |  |  |  |  | 5 | my $sources = $config->{source}; | 
| 63 | 3 | 50 | 33 |  |  | 22 | $sources    = [ $sources ] if !ref $sources or ref $sources ne 'ARRAY'; | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 3 |  |  |  |  | 6 | my @pods; | 
| 66 | 3 |  |  |  |  | 5 | for my $source ( @{$sources} ) { | 
|  | 3 |  |  |  |  | 6 |  | 
| 67 | 3 | 50 |  |  |  | 11 | die('No type in source.') unless (exists $source->{type}); | 
| 68 | 3 |  |  |  |  | 13 | $self->debug('100: ' . $source->{type} ); | 
| 69 | 3 |  |  |  |  | 23 | my $source_obj = EPublisher::Source->new( $source ); | 
| 70 | 3 |  |  |  |  | 12 | $source_obj->publisher( $self ); | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 3 |  |  |  |  | 14 | my @pod_source = $source_obj->load_source; | 
| 73 | 3 | 50 | 33 |  |  | 46 | @pod_source = ({ pod => '', title => '', filename => '' }) if !@pod_source || !$pod_source[0]; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 3 |  |  |  |  | 11 | $self->debug('101: ' . substr join( "", map{ $_->{pod} }@pod_source ), 0, 50 ); | 
|  | 3 |  |  |  |  | 29 |  | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 3 |  |  |  |  | 40 | push @pods, @pod_source; | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 3 |  |  |  |  | 15 | $config->{target}->{source} = \@pods; | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | # deploy the project | 
| 83 | 3 |  |  |  |  | 16 | $self->debug('200: ' . $config->{target}->{type} ); | 
| 84 | 3 |  |  |  |  | 80 | my $target = EPublisher::Target->new( $config->{target} ); | 
| 85 | 3 |  |  |  |  | 19 | $target->publisher( $self ); | 
| 86 | 3 |  |  |  |  | 13 | $target->deploy; | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | sub _debug{ | 
| 91 | 6 |  |  | 6 |  | 18 | 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 | 21 | my ($self,$message) = @_; | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 9 | 100 |  |  |  | 38 | return if !$self->{DEBUG}; | 
| 105 | 3 |  |  |  |  | 12 | $self->{__debug}->($message); | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | sub _config{ | 
| 109 | 11 |  |  | 11 |  | 1888 | my ($self,$bool,$data) = @_; | 
| 110 |  |  |  |  |  |  |  | 
| 111 | 11 | 100 | 100 |  |  | 90 | if ( $bool and $data ) { | 
|  |  | 100 | 100 |  |  |  |  | 
| 112 | 1 |  |  |  |  | 4 | $self->{__config} = $data; | 
| 113 |  |  |  |  |  |  | } | 
| 114 |  |  |  |  |  |  | elsif( !$self->{__config} or $bool ){ | 
| 115 | 4 | 100 |  |  |  | 13 | unless( $self->config ){ | 
| 116 | 1 |  |  |  |  | 148 | croak "no config file given!"; | 
| 117 |  |  |  |  |  |  | } | 
| 118 | 3 |  |  |  |  | 8 | $self->{__config} = EPublisher::Config->get_config( $self->config ); | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 10 |  |  |  |  | 29 | return $self->{__config}; | 
| 122 |  |  |  |  |  |  | } | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | 1; | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | __END__ |