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   63 use strict;
  20         20  
  20         396  
3 20     20   53 use warnings;
  20         20  
  20         397  
4 20     20   55 use Carp qw/croak/;
  20         20  
  20         695  
5              
6 20     20   57 use Exporter 'import';
  20         20  
  20         1566  
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 53 my $caller = caller;
16 20     20   69 no strict 'refs';
  20         21  
  20         3722  
17 20         51 *{"$caller\::$_"} = \&_abstract for @_;
  30         155  
18             }
19              
20             sub add_accessors {
21 90     90 0 220 my $class = caller;
22 90         277 _add_accessor( $class, $_ ) for @_;
23             }
24              
25             sub _add_accessor {
26 90     90   109 my ( $class, $reader ) = @_;
27 90         130 my $prop = "_$reader";
28              
29             my $psub = sub {
30 339     339   312 my $self = shift;
31 339 100       1236 ($self->{ $prop }) = @_ if @_;
32 339         3369239 return $self->{ $prop };
33 90         320 };
34              
35             my $rsub = sub {
36 298     298   1929 my $self = shift;
37 298         691 return $self->$prop();
38 90         207 };
39              
40 20     20   72 no strict 'refs';
  20         23  
  20         1370  
41 90         77 *{"$class\::$reader"} = $rsub;
  90         351  
42 90         72 *{"$class\::$prop"} = $psub;
  90         434  
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.