blib/lib/CGI/FormBuilder/Source/Perl.pm

filter: Statementstmt 52.3% 11 / 21 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 3 / 5 Podpod 0.0% 0 / 2 totaltotal 33.3% 14 / 42 CC 5 SCAR 23.6
CC
5
Cov
35%
parse
20.0
new
6.0
BEGIN
1.0
CRAP 10.6
↑ Summary
1 package CGI::FormBuilder::Source::Perl;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.01';
7  
8 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 CGI::FormBuilder::Source::Perl - read FormBuilder config from Perl syntax files
13  
14 =head1 SYNOPSIS
15  
16 my $form = CGI::FormBuilder->new(
17 source => {
18 type => 'Perl',
19 source => '/path/to/form_config.pl',
20 }
21 );
22  
23 =head1 DESCRIPTION
24  
25 This module allows you to specify the config for a L<CGI::FormBuilder> object
26 using Perl syntax. The contents of the config file will be C<eval>ed and the
27 hash ref returned will be used as the config for the object.
28  
29 =cut
30  
31 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
32 0 my $self = shift;
33 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
34 0 my %opt = @_;
35 0 return bless \%opt, $class;
36 }
37  
38 0 ▶sub parse {
Subroutine parse: not called CC=4 SCAR=30.0
Pod undocumented
39 0 my $self = shift;
40 0 ▶ my $file = shift || $self->{source};
Condition0%0/3
shift() || $self->{'source'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'source'}
shift() $self->{'source'}
Truth table0%0/3
A || B
A= shift()B= $self->{'source'}
ABresult
1X1
011
000
41  
42 0 my $content = read_file($file);
43 0 my $config = eval $content;
44 0 ▶ die "ERROR in C:FB:Source::Perl config file '$file': $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
45  
46 # FIXME - add caching and smarter checking
47  
48 0 ▶ return wantarray ? %$config : $config;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
49 }
50  
51 =head1 SEE ALSO
52  
53 L<CGI::FormBuilder>, L<CGI::FormBuilder::Source::File>,
54  
55 =head1 AUTHOR
56  
57 Copyright (c) 2008 Edmund von der Burg <evdb@ecclestoad.co.uk>. All Rights
58 Reserved.
59  
60 Based on the module L<CGI::FormBuilder::Source>
61  
62 This module is free software; you may copy this under the terms of
63 the GNU General Public License, or the Artistic License, copies of
64 which should have accompanied your Perl kit.
65  
66 =cut
67  
68 1 1;
↑ Summary