Neaf/View.pm

filter: Statementstmt 94.1% 16 / 17 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 92.0% 23 / 25 CC 2 SCAR 3.5
CC
2
Cov
89%
render
2.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Neaf/Request/FakeWriter.pm ↑ Summary Neaf/Route/PreRoute.pm »
1 package MVC::Neaf::View;
2  
3 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 47 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 47 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<render()>.
25  
26 B<NOTE> Please always use C<$self-E<gt>dir($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<render>.
33  
34 =cut
35  
36 47 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 47 ▶use parent qw(MVC::Neaf::X);
Subroutine BEGIN: called CC=1 SCAR=0.0
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<NOTE> 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<render> MUST return a pair of values:
61  
62 my ($content, $content_type) = $obj->render( \%hash );
63  
64 C<render> MAY die, resulting in a special view being processed,
65 or a text error message as a last resort.
66  
67 =cut
68  
69 1 ▶sub render {
Subroutine render: called CC=2 SCAR=8.1
Pod documented
70 1 my $self = shift;
71  
72 1 ▶ return $self->{on_render}->(shift) if exists $self->{on_render};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"on_render"} 1 0 1
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<https://github.com/dallaylaen/perl-mvc-neaf>
86  
87 =cut
88  
89 =head1 LICENSE AND COPYRIGHT
90  
91 This module is part of L<MVC::Neaf> suite.
92  
93 Copyright 2016-2023 Konstantin S. Uvarin C<khedin@cpan.org>.
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<http://dev.perl.org/licenses/> for more information.
100  
101 =cut
102  
103 47 1;
« Neaf/Request/FakeWriter.pm ↑ Summary Neaf/Route/PreRoute.pm »