File Coverage

blib/lib/MVC/Neaf/View.pm
Criterion Covered Total %
statement 14 15 93.3
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 21 23 91.3


line stmt bran cond sub pod time code
1             package MVC::Neaf::View;
2              
3 47     47   21626 use strict;
  47         126  
  47         1357  
4 47     47   260 use warnings;
  47         107  
  47         2060  
5             our $VERSION = '0.2901';
6              
7             =head1 NAME
8              
9             MVC::Neaf::View - Base [V]iew for Not Even A Framework.
10              
11             =head1 DESCRIPTION
12              
13             Subclass this class to make your own content rendering engine under Neaf.
14              
15             Neaf stands for Not Even A Framework. It works by
16             (1) getting a hash from a sub which is pathetically called Controller,
17             and (2) passing that hash over to an object called View.
18              
19             A subset of hash keys is used to control the framework's own behaviour.
20             Such -keys -are -prefixed -with -a -dash for greater visibility.
21             These keys are NOT guaranteed to get to your engine,
22             unless documentation explicitly states otherwise.
23              
24             View in turn has a single method called C.
25              
26             B Please always use C<$self-Edir($path)> whenever dealing with
27             templates or resources when subclassing this class.
28              
29             =head1 METHODS
30              
31             As of current, the one and only method (except constructor)
32             is needed, C.
33              
34             =cut
35              
36 47     47   289 use Carp;
  47         124  
  47         2652  
37 47     47   334 use parent qw(MVC::Neaf::X);
  47         100  
  47         360  
38              
39             =head2 new( %options )
40              
41             Options may include:
42              
43             =over
44              
45             =item * on_render - a callback to be called in the render sub was not defined.
46             Useful if you are too lazy to subclass.
47              
48             =item * neaf_base_path - a directory to calculate relative template paths from.
49              
50             =back
51              
52             B The constructor of this particular class happily encloses itself
53             over any data one gives to it. No checks are performed.
54             This may change in the future.
55              
56             =cut
57              
58             =head2 render( \%hash )
59              
60             C MUST return a pair of values:
61              
62             my ($content, $content_type) = $obj->render( \%hash );
63              
64             C MAY die, resulting in a special view being processed,
65             or a text error message as a last resort.
66              
67             =cut
68              
69             sub render {
70 1     1 1 8 my $self = shift;
71              
72 1 50       15 return $self->{on_render}->(shift) if exists $self->{on_render};
73              
74 0           croak( (ref $self)."->render() unimplemented (in MVC::Neaf::View)" );
75             };
76              
77             =head1 CONCLUSION
78              
79             There are a lot of templating engines, serializers etc. in the world.
80             The author of this tiny framework is not able to keep an eye on all of them.
81             Thus making your custom views is encouraged.
82              
83             Please send patches, improvements, suggestions and bug reports to
84              
85             L
86              
87             =cut
88              
89             =head1 LICENSE AND COPYRIGHT
90              
91             This module is part of L suite.
92              
93             Copyright 2016-2023 Konstantin S. Uvarin C.
94              
95             This program is free software; you can redistribute it and/or modify it
96             under the terms of either: the GNU General Public License as published
97             by the Free Software Foundation; or the Artistic License.
98              
99             See L for more information.
100              
101             =cut
102              
103             1;