File Coverage

blib/lib/App/Embra.pm
Criterion Covered Total %
statement 68 68 100.0
branch 15 26 57.6
condition 2 6 33.3
subroutine 16 16 100.0
pod n/a
total 101 116 87.0


line stmt bran cond sub pod time code
1 24     24   138519 use strict;
  24         46  
  24         734  
2 24     24   102 use warnings;
  24         36  
  24         937  
3              
4             package App::Embra;
5             $App::Embra::VERSION = '0.001'; # TRIAL
6             # ABSTRACT: build a site from parts
7              
8 24     24   1394 use Method::Signatures;
  24         116773  
  24         211  
9 24     24   10075 use Moo;
  24         14908  
  24         156  
10              
11              
12             with 'App::Embra::Role::Logging';
13              
14             around '_build_log_prefix' => func( $orig, $self ) {
15             return "[Embra] ";
16             };
17              
18             around '_build_logger' => func( $orig, $self ) {
19             return Log::Any->get_logger;
20             };
21              
22              
23             has 'plugins' => (
24             is => 'ro',
25             default => sub{[]},
26             );
27              
28              
29             has 'files' => (
30             is => 'ro',
31             default => sub{[]},
32             );
33              
34              
35 24 50 33 24   958647 method from_config_mvp_sequence( $class:, Config::MVP::Sequence :$sequence ) {
  6 50 33 6   32719  
  6 50       38  
  6         17  
  6         103  
  6         25852  
  6         32  
  6         23  
36 6         14 my $payload = {};
37 6 50       34 if ( my $root_section = $sequence->section_named( '_' ) ) {
38 6         494 $payload = $root_section->payload;
39             }
40 6         83 my $creatura = $class->new( $payload );
41 6         45 for my $plugin_section ( $sequence->sections ) {
42 13 100       781 next if $plugin_section->name eq '_';
43 7         222 $plugin_section->package->register_plugin(
44             name => $plugin_section->name,
45             args => $plugin_section->payload,
46             embra => $creatura,
47             );
48             }
49 6         191 $creatura;
50             }
51              
52              
53 24 50   24   200590 method add_plugin( $plugin where { $_->DOES( "App::Embra::Role::Plugin" ) } ) {
  24 100   24   20747  
  24 50   12   278  
  24     12   125  
  12         93  
  12         1336  
  12         49  
  12         21  
  12         15  
  12         21  
  12         121  
  11         295  
54 11         17 push @{ $self->plugins}, $plugin;
  11         84  
55             }
56              
57              
58 24 50   24   62501 method find_plugin( $class ) {
  1 50   1   1033  
  1         14  
  1         2  
  1         4  
59 1         2 ( grep { ref $_ eq $class } @{ $self->plugins } )[0];
  1         5  
  1         6  
60             }
61              
62              
63 24 50   24   16178 method collate {
  5     5   9830  
  5         25  
64 5         154 $self->debug( 'collating' );
65 5         39 $_->gather_files for $self->plugins_with( -FileGatherer );
66 5         180 $_->prune_files for $self->plugins_with( -FilePruner );
67 5         95 $_->transform_files for $self->plugins_with( -FileTransformer );
68 5         79 $_->assemble_files for $self->plugins_with( -FileAssembler );
69 5         72 $_->publish_site for $self->plugins_with( -SitePublisher );
70             }
71              
72              
73 24 50   24   51390 method plugins_with( $rolename ) {
  28 50   28   2497  
  28         76  
  28         37  
  28         55  
74 28         101 $rolename =~ s/^-/App::Embra::Role::/xms;
75 28         34 return grep { $_->does( $rolename ) } @{ $self->plugins };
  33         249  
  28         88  
76             }
77              
78              
79             1;
80              
81             __END__
82              
83             =pod
84              
85             =encoding UTF-8
86              
87             =head1 NAME
88              
89             App::Embra - build a site from parts
90              
91             =head1 VERSION
92              
93             version 0.001
94              
95             =head1 DESCRIPTION
96              
97             App::Embra collates your content into a static website.
98              
99             =head1 ATTRIBUTES
100              
101             =head2 plugins
102              
103             The objects which will help you build your site. An array reference of objects which implement L<App::Embra::Role::Plugin>.
104              
105             =head2 files
106              
107             Your site content. An array reference of L<App::Embra::File> instances. Plugins add, remove, read, and alter files via this attribute.
108              
109             =head1 METHODS
110              
111             =head2 from_config_mvp_sequence
112              
113             my $embra = App::Embra->from_config_mvp_sequence( $sequence );
114              
115             Returns a new C<App::Embra> with its attributes & plugins taken from a L<Config::MVP::Sequence>. Called by the L<command-line base class|App::Embra::App::Command> whenever L<embra> is run.
116              
117             =head2 add_plugin
118              
119             $embra->add_plugin( $plugin );
120              
121             Adds a plugin to L<C</plugins>>. C<$plugin> must implement L<App::Embra::Role::Plugin>.
122              
123             =head2 find_plugin
124              
125             my $plugin = $embra->find_plugin( $class );
126              
127             Returns the first plugin in L<C</plugins>> with class C<$class>. Returns an emtpy list if no plugin with class C<$class> is present
128              
129             =head2 collate
130              
131             $embra->collate;
132              
133             Assembles your site. Plugins are called in this order:
134              
135             =over 4
136              
137             =item *
138              
139             gather
140              
141             =item *
142              
143             prune
144              
145             =item *
146              
147             transform
148              
149             =item *
150              
151             assemble
152              
153             =item *
154              
155             publish
156              
157             =back
158              
159             For each of the types, all plugins which implement C<< App::Embra::Role::File<Type> >> have their C<< <type>_files> >> method called, in ths same order as they appear in L<C</plugins>>.
160              
161             =head2 plugins_with
162              
163             say for $embra->plugins_with( $rolename );
164              
165             Returns all elements of L<C</plugins>> which implement C<$rolename>. Role names should be fully specified; as a shorthand, you can pass C<<-<relative_role_name> >> and it will be treated as if you had specified C<< App::Embra::Role::<relative_role_name> >>.
166              
167             =head1 SEE ALSO
168              
169             =over 4
170              
171             =item *
172              
173             L<Blio>
174              
175             =item *
176              
177             L<jekyll|http://jekyllrb.com/>
178              
179             =item *
180              
181             L<Octopress|https://github.com/imathis/octopress#readme>
182              
183             =back
184              
185             =head1 AUTHOR
186              
187             Daniel Holz <dgholz@gmail.com>
188              
189             =head1 COPYRIGHT AND LICENSE
190              
191             This software is copyright (c) 2015 by Daniel Holz.
192              
193             This is free software; you can redistribute it and/or modify it under
194             the same terms as the Perl 5 programming language system itself.
195              
196             =cut