File Coverage

blib/lib/Rapi/Blog/Util/ppRender.pm
Criterion Covered Total %
statement 15 29 51.7
branch 0 10 0.0
condition 0 5 0.0
subroutine 5 7 71.4
pod n/a
total 20 51 39.2


line stmt bran cond sub pod time code
1             package Rapi::Blog::Util::ppRender;
2 2     2   13 use strict;
  2         5  
  2         52  
3 2     2   10 use warnings;
  2         5  
  2         51  
4              
5             # ABSTRACT: Render method dispatch to template process class
6              
7 2     2   914 use Moo;
  2         23617  
  2         23  
8 2     2   7991 use Types::Standard qw(:all);
  2         61259  
  2         27  
9 2     2   78894 use RapidApp::Util qw(:all);
  2         6  
  2         1536  
10             require Module::Runtime;
11              
12             has '_base_namespace', is => 'ro', isa => Str, default => sub {'Rapi::Blog::Template::Postprocessor'};
13              
14             has '_post_processor', is => 'rw', isa => Maybe[Str], default => sub {undef};
15              
16              
17             sub AUTOLOAD {
18 0     0     my $self = shift;
19 0           my $method = (reverse(split('::',our $AUTOLOAD)))[0];
20 0           $self->_call_process($method,@_)
21             }
22              
23             sub _call_process {
24 0     0     my ($self, $processor, $content) = @_;
25            
26 0 0         die "ppRender: no Postprocessor and/or content supplied" unless ($processor);
27            
28             # Allow us to be called with or without the name of the post-processor
29 0 0 0       if(! $content && $self->_post_processor) {
30 0           $content = $processor;
31 0           $processor = $self->_post_processor
32             }
33            
34 0   0       $content //= '';
35            
36 0 0         my $class = $processor =~ /\:\:/
37             ? $processor
38             : join('::',$self->_base_namespace,$processor);
39            
40 0           Module::Runtime::require_module($class);
41              
42 0 0         $class->can('process') or die "$class is not a Template Processor class without a ->process method";
43              
44 0 0         my $content_ref = ref $content ? $content : \$content;
45              
46 0           $class->process($content_ref)
47             }
48              
49              
50              
51              
52             1;
53              
54              
55             __END__
56              
57             =head1 NAME
58              
59             Rapi::Blog::Util::ppRender - Render method dispatch to template post-processor class
60              
61              
62             =head1 DESCRIPTION
63              
64             Caller to Template Postprocessor class
65              
66             =head1 SEE ALSO
67              
68             =over
69              
70             =item *
71              
72             L<Rapi::Blog>
73              
74             =back
75              
76             =head1 AUTHOR
77              
78             Henry Van Styn <vanstyn@cpan.org>
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             This software is copyright (c) 2019 by IntelliTree Solutions llc.
83              
84             This is free software; you can redistribute it and/or modify it under
85             the same terms as the Perl 5 programming language system itself.
86              
87             =cut