Factory/Fields.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 100% 45 / 45 CC 5 SCAR 7.9
CC
5
Cov
100%
all
3.0
get
3.0
BEGIN
1.0
CRAP 2.2
↑ Summary Factory.pm »
1 package DBIx::Class::Factory::Fields;
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 =encoding utf8
7  
8 =head1 NAME
9  
10 DBIx::Class::Factory::Fields - fields for DBIx::Class::Factory class
11  
12 =head1 DESCRIPTION
13  
14 Every callback used in L<DBIx::Class::Factory> gets a C<DBIx::Class::Factory::Fields> instance as an argument.
15  
16 =cut
17  
18 =head1 METHODS
19  
20 =over
21  
22 =item B<new>
23  
24 Constructor. You shouldn't call it explicitly.
25  
26 =cut
27  
28 18 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
29 18 my ($class, @params) = @_;
30  
31 18 my $instance = bless({}, $class);
32 18 $instance->_init(@params);
33  
34 18 return $instance;
35 }
36  
37 =item B<all>
38  
39 Returns hashref with all fields that are not excluded
40  
41 =cut
42  
43 18 ▶sub all {
Subroutine all: called CC=3 SCAR=11.0
Pod documented
44 18 my ($self) = @_;
45  
46 18 my %result;
47 18 foreach my $field (keys %{$self->{init_fields}}) {
48 39 ▶ unless (defined $self->{exclude_set}->{$field}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"exclude_set"}{$field}) 38 1 39
49 38 $result{$field} = $self->get($field);
50 }
51 }
52  
53 18 return \%result;
54 }
55  
56 =item B<get>
57  
58 Get the value of the field.
59  
60 $fields->get('name');
61  
62 =cut
63  
64 41 ▶sub get {
Subroutine get: called CC=3 SCAR=11.0
Pod documented
65 41 my ($self, $field) = @_;
66  
67 41 ▶ unless (exists $self->{processed_fields}->{$field}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"processed_fields"}{$field}) 39 2 41
68 39 my $value = $self->{init_fields}->{$field};
69  
70 39 ▶ if (ref($value) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "CODE") 17 22 39
71 17 $value = $value->($self);
72 }
73  
74 39 $self->{processed_fields}->{$field} = $value;
75 }
76  
77 41 return $self->{processed_fields}->{$field};
78 }
79  
80 =back
81  
82 =cut
83  
84 # PRIVATE METHODS
85  
86 18 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
87 18 my ($self, $fields, $exclude_set) = @_;
88  
89 18 $self->{init_fields} = $fields;
90 18 $self->{processed_fields} = {};
91 18 $self->{exclude_set} = $exclude_set;
92  
93 18 return;
94 }
95  
96 =head1 AUTHOR
97  
98 Vadim Pushtaev, C<pushtaev@cpan.org>
99  
100 =head1 BUGS AND FEATURES
101  
102 Bugs are possible, feature requests are welcome. Write me as soon as possible.
103  
104 =head1 LICENSE AND COPYRIGHT
105  
106 Copyright 2015 Vadim Pushtaev.
107  
108 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
109  
110 =cut
111  
112 1 1;
↑ Summary Factory.pm »