File Coverage

blib/lib/HTML/MasonX/Free/Component.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition 1 2 50.0
subroutine 5 5 100.0
pod 0 2 0.0
total 23 26 88.4


line stmt bran cond sub pod time code
1 3     3   1519 use strict;
  3         8  
  3         92  
2 3     3   21 use warnings;
  3         13  
  3         134  
3             package HTML::MasonX::Free::Component 0.007;
4             # ABSTRACT: a component with a "main" method, not just a bunch of text
5              
6 3     3   19 use parent 'HTML::Mason::Component::FileBased';
  3         5  
  3         20  
7              
8             #pod =head1 OVERVIEW
9             #pod
10             #pod In concept, a Mason component is broken down into special blocks (like once,
11             #pod shared, init), methods, and subcomponents. When you render a Mason component,
12             #pod using it as a template, you aren't calling one of its methods or blocks.
13             #pod Instead, all the stray code and text that was found I<outside> all of those is
14             #pod concatenated together and run.
15             #pod
16             #pod This is sort of a mess.
17             #pod
18             #pod If you use HTML::MasonX::Free::Component as your component class instead,
19             #pod rendering the component will call its C<main> method instead of all that other
20             #pod junk. This component class extends HTML::Mason::Component::FileBased. If this
21             #pod is a problem because of your esoteric Mason configuration, don't panic. Just
22             #pod read the source. Seriously, it's tiny.
23             #pod
24             #pod This component class is meant to work well with
25             #pod L<HTML::MasonX::Free::Compiler>, which will let you throw a syntax exception if
26             #pod there's any significant content outside of blocks, and which can apply
27             #pod C<default_method_to_call> to calls found when compiling.
28             #pod
29             #pod You can pass a C<default_method_to_call> argument to the constructor for this
30             #pod class, but it's not all that easy to get where you need it, so maybe you should
31             #pod stick with the default: C<main>
32             #pod
33             #pod =cut
34              
35             sub new {
36 23     23 0 92 my ($class, %arg) = @_;
37 23   50     112 my $default_method_to_call = delete $arg{default_method_to_call} || 'main';
38 23         95 my $self = $class->SUPER::new(%arg);
39 23         837 $self->{default_method_to_call} = $default_method_to_call;
40 23         393 return $self;
41             }
42              
43             sub run {
44 23     23 0 1229 my $self = shift;
45 23         42 $self->{mfu_count}++;
46 23         95 $self->call_method($self->{default_method_to_call} => @_);
47             }
48              
49             1;
50              
51             __END__
52              
53             =pod
54              
55             =encoding UTF-8
56              
57             =head1 NAME
58              
59             HTML::MasonX::Free::Component - a component with a "main" method, not just a bunch of text
60              
61             =head1 VERSION
62              
63             version 0.007
64              
65             =head1 OVERVIEW
66              
67             In concept, a Mason component is broken down into special blocks (like once,
68             shared, init), methods, and subcomponents. When you render a Mason component,
69             using it as a template, you aren't calling one of its methods or blocks.
70             Instead, all the stray code and text that was found I<outside> all of those is
71             concatenated together and run.
72              
73             This is sort of a mess.
74              
75             If you use HTML::MasonX::Free::Component as your component class instead,
76             rendering the component will call its C<main> method instead of all that other
77             junk. This component class extends HTML::Mason::Component::FileBased. If this
78             is a problem because of your esoteric Mason configuration, don't panic. Just
79             read the source. Seriously, it's tiny.
80              
81             This component class is meant to work well with
82             L<HTML::MasonX::Free::Compiler>, which will let you throw a syntax exception if
83             there's any significant content outside of blocks, and which can apply
84             C<default_method_to_call> to calls found when compiling.
85              
86             You can pass a C<default_method_to_call> argument to the constructor for this
87             class, but it's not all that easy to get where you need it, so maybe you should
88             stick with the default: C<main>
89              
90             =head1 PERL VERSION
91              
92             This library should run on perls released even a long time ago. It should work
93             on any version of perl released in the last five years.
94              
95             Although it may work on older versions of perl, no guarantee is made that the
96             minimum required version will not be increased. The version may be increased
97             for any reason, and there is no promise that patches will be accepted to lower
98             the minimum required perl.
99              
100             =head1 AUTHOR
101              
102             Ricardo Signes <cpan@semiotic.systems>
103              
104             =head1 COPYRIGHT AND LICENSE
105              
106             This software is copyright (c) 2022 by Ricardo Signes.
107              
108             This is free software; you can redistribute it and/or modify it under
109             the same terms as the Perl 5 programming language system itself.
110              
111             =cut