File Coverage

blib/lib/Child/Util.pm
Criterion Covered Total %
statement 36 38 94.7
branch 2 2 100.0
condition n/a
subroutine 11 12 91.6
pod 0 2 0.0
total 49 54 90.7


line stmt bran cond sub pod time code
1             package Child::Util;
2 20     20   78 use strict;
  20         31  
  20         513  
3 20     20   61 use warnings;
  20         23  
  20         374  
4 20     20   58 use Carp qw/croak/;
  20         25  
  20         799  
5              
6 20     20   75 use Exporter 'import';
  20         33  
  20         1495  
7             our @EXPORT = qw/add_accessors add_abstract/;
8              
9             sub _abstract {
10 0     0   0 my $class = shift;
11 0         0 croak "$class does not implement this function."
12             }
13              
14             sub add_abstract {
15 20     20 0 43 my $caller = caller;
16 20     20   77 no strict 'refs';
  20         20  
  20         3098  
17 20         49 *{"$caller\::$_"} = \&_abstract for @_;
  30         177  
18             }
19              
20             sub add_accessors {
21 90     90 0 244 my $class = caller;
22 90         236 _add_accessor( $class, $_ ) for @_;
23             }
24              
25             sub _add_accessor {
26 90     90   109 my ( $class, $reader ) = @_;
27 90         129 my $prop = "_$reader";
28              
29             my $psub = sub {
30 339     339   323 my $self = shift;
31 339 100       1234 ($self->{ $prop }) = @_ if @_;
32 339         5917391 return $self->{ $prop };
33 90         331 };
34              
35             my $rsub = sub {
36 298     298   1865 my $self = shift;
37 298         829 return $self->$prop();
38 90         213 };
39              
40 20     20   98 no strict 'refs';
  20         20  
  20         1147  
41 90         83 *{"$class\::$reader"} = $rsub;
  90         357  
42 90         88 *{"$class\::$prop"} = $psub;
  90         456  
43             }
44              
45             1;
46              
47             =head1 NAME
48              
49             Child::Util - Utility functions for L>Child>
50              
51             =head1 HISTORY
52              
53             Most of this was part of L intended for use in the L
54             project. Fennec is being broken into multiple parts, this is one such part.
55              
56             =head1 FENNEC PROJECT
57              
58             This module is part of the Fennec project. See L for more details.
59             Fennec is a project to develop an extendable and powerful testing framework.
60             Together the tools that make up the Fennec framework provide a potent testing
61             environment.
62              
63             The tools provided by Fennec are also useful on their own. Sometimes a tool
64             created for Fennec is useful outside the greater framework. Such tools are
65             turned into their own projects. This is one such project.
66              
67             =over 2
68              
69             =item L - The core framework
70              
71             The primary Fennec project that ties them all together.
72              
73             =back
74              
75             =head1 AUTHORS
76              
77             Chad Granum L
78              
79             =head1 COPYRIGHT
80              
81             Copyright (C) 2010 Chad Granum
82              
83             Child is free software; Standard perl licence.
84              
85             Child is distributed in the hope that it will be useful, but WITHOUT
86             ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
87             FOR A PARTICULAR PURPOSE. See the license for more details.