File Coverage

blib/lib/Moonshine/Magic.pm
Criterion Covered Total %
statement 50 52 96.1
branch 1 4 25.0
condition 0 2 0.0
subroutine 14 14 100.0
pod n/a
total 65 72 90.2


line stmt bran cond sub pod time code
1             package Moonshine::Magic;
2              
3 4     4   82900 use strict;
  4         6  
  4         90  
4 4     4   11 use warnings;
  4         6  
  4         74  
5              
6 4     4   1542 use BEGIN::Lift;
  4         16189  
  4         93  
7 4     4   1785 use Moonshine::Element;
  4         91894  
  4         292  
8              
9             =head1 NAME
10              
11             Moonshine::Magic - d[ o_0 ]b - has, extends, lazy_components
12              
13             =head1 VERSION
14              
15             Version 0.05
16              
17             =cut
18              
19             our $VERSION = '0.05';
20              
21             =head1 SYNOPSIS
22              
23             use Moonshine::Magic;
24              
25             =head1 Imports
26              
27             =head2 extends
28              
29             extends 'Moonshine::Component';
30             # BEGIN { @ISA = ('Moonshine::Component') }
31              
32             =head2 has
33              
34             has (
35             'modify_spec' => sub { { switch => 0, switch_base => 0 } },
36             );
37              
38             # BEGIN { @HAS = ( 'modify_spec' => sub { { switch => 0, switch_base => 0 } } }
39             # $self->modify_spec
40              
41             =head2 lazy_components
42              
43             lazy_components (qw/p span h1/);
44             # $self->span() -
45              
46             =cut
47              
48             sub import {
49 9     9   894 my $caller = caller;
50              
51             BEGIN::Lift::install(
52             ($caller, 'extends') => sub {
53 4     4   23 no strict 'refs';
  4         4  
  4         315  
54 8     8   637 @{"${caller}::ISA"} = @_;
  8         1032  
55             }
56 9         46 );
57              
58             BEGIN::Lift::install(
59             ($caller, 'has') => sub {
60 2     2   12 my %args = @_;
61 4     4   15 no strict 'refs';
  4         6  
  4         94  
62 4     4   13 no warnings 'once';
  4         8  
  4         501  
63 2         5 %{"${caller}::HAS"} = %args;
  2         8  
64 2         3 for my $arg (keys %args) {
65 4     6   8 *{"${caller}::${arg}"} = sub { return $args{$arg}->(); };
  4         58  
  3         1050  
66             }
67             }
68 9         698 );
69              
70             BEGIN::Lift::install(
71             ($caller, 'lazy_components') => sub {
72 1     1   4 my @lazy_components = @_;
73 4     4   17 no strict 'refs';
  4         3  
  4         109  
74 4     4   12 no warnings 'once';
  4         4  
  4         724  
75 1         2 for my $component (@lazy_components) {
76 1         646 *{"${caller}::${component}"} = sub {
77 3         3555 my $self = shift;
78            
79 3         5 my ($base_args, $build_args) = ();
80 3 50       12 if ($self->can('validate_build')) {
81             ( $base_args, $build_args ) = $self->validate_build({
82             params => $_[0] // {},
83             spec => {
84             tag => { default => $component },
85             data => 0,
86 0 0 0     0 ( $_[1] ? %{ $_[1] } : () )
  0         0  
87             }
88             });
89             } else {
90 3         4 $base_args = { tag => $component, %{ $_[0] } };
  3         9  
91             }
92              
93 3         12 return Moonshine::Element->new($base_args);
94             }
95 1         3 }
96             }
97 9         564 );
98             }
99              
100             =head1 AUTHOR
101              
102             Robert Acock, C<< >>
103              
104             =head1 BUGS
105              
106             Please report any bugs or feature requests to C, or through
107             the web interface at L. I will be notified, and then you'll
108             automatically be notified of progress on your bug as I make changes.
109              
110             =head1 SUPPORT
111              
112             You can find documentation for this module with the perldoc command.
113              
114             perldoc Moonshine::Magic
115              
116             You can also look for information at:
117              
118             =over 4
119              
120             =item * RT: CPAN's request tracker (report bugs here)
121              
122             L
123              
124             =item * AnnoCPAN: Annotated CPAN documentation
125              
126             L
127              
128             =item * CPAN Ratings
129              
130             L
131              
132             =item * Search CPAN
133              
134             L
135              
136             =back
137              
138              
139             =head1 ACKNOWLEDGEMENTS
140              
141              
142             =head1 LICENSE AND COPYRIGHT
143              
144             Copyright 2017 Robert Acock.
145              
146             This program is free software; you can redistribute it and/or modify it
147             under the terms of the the Artistic License (2.0). You may obtain a
148             copy of the full license at:
149              
150             L
151              
152             Any use, modification, and distribution of the Standard or Modified
153             Versions is governed by this Artistic License. By using, modifying or
154             distributing the Package, you accept this license. Do not use, modify,
155             or distribute the Package, if you do not accept this license.
156              
157             If your Modified Version has been derived from a Modified Version made
158             by someone other than you, you are nevertheless required to ensure that
159             your Modified Version complies with the requirements of this license.
160              
161             This license does not grant you the right to use any trademark, service
162             mark, tradename, or logo of the Copyright Holder.
163              
164             This license includes the non-exclusive, worldwide, free-of-charge
165             patent license to make, have made, use, offer to sell, sell, import and
166             otherwise transfer the Package with respect to any patent claims
167             licensable by the Copyright Holder that are necessarily infringed by the
168             Package. If you institute patent litigation (including a cross-claim or
169             counterclaim) against any party alleging that the Package constitutes
170             direct or contributory patent infringement, then this Artistic License
171             to you shall terminate on the date that such litigation is filed.
172              
173             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
174             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
175             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
176             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
177             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
178             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
179             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
180             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
181              
182              
183             =cut
184              
185             1; # End of Moonshine::Magic