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   80 use strict;
  20         20  
  20         567  
3 20     20   72 use warnings;
  20         27  
  20         431  
4 20     20   82 use Carp qw/croak/;
  20         40  
  20         848  
5              
6 20     20   81 use Exporter 'import';
  20         31  
  20         1744  
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 38 my $caller = caller;
16 20     20   89 no strict 'refs';
  20         20  
  20         3824  
17 20         43 *{"$caller\::$_"} = \&_abstract for @_;
  30         155  
18             }
19              
20             sub add_accessors {
21 90     90 0 252 my $class = caller;
22 90         279 _add_accessor( $class, $_ ) for @_;
23             }
24              
25             sub _add_accessor {
26 90     90   2531 my ( $class, $reader ) = @_;
27 90         136 my $prop = "_$reader";
28              
29             my $psub = sub {
30 339     339   576 my $self = shift;
31 339 100       1656 ($self->{ $prop }) = @_ if @_;
32 339         4618696 return $self->{ $prop };
33 90         357 };
34              
35             my $rsub = sub {
36 298     298   3910 my $self = shift;
37 298         1095 return $self->$prop();
38 90         225 };
39              
40 20     20   104 no strict 'refs';
  20         70  
  20         1606  
41 90         97 *{"$class\::$reader"} = $rsub;
  90         1549  
42 90         84 *{"$class\::$prop"} = $psub;
  90         517  
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.