HTMLFormHandler/Model.pm

filter: Statementstmt 40.0% 12 / 30 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 2 totaltotal 35.7% 15 / 42 CC 5 SCAR 18.4
CC
5
Cov
35%
update_model
12.0
_fieldname2obj
6.0
build_item
6.0
CRAP 6.3
« HTMLFormHandler.pm ↑ Summary
1 package User::Config::UI::HTMLFormHandler::Model;
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 ▶use HTML::FormHandler::Model;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.01_01';
9 1 $VERSION = eval $VERSION; # see L<perlmodstyle>
10  
11 =pod
12  
13 =head1 NAME
14  
15 User::Config::UI::HTMLFormHandler::Model - a model for L<HTML::FormHandler>
16 interfacing the Form-entries with L<User::Config>.
17  
18 =head1 SYNOPSIS
19  
20 package MyApp::Form;
21 use HTML::FormHandler::Moose;
22 extends User::Config::UI::HTMLFormHandler::Model;
23  
24 =head1 DESCRIPTION
25  
26 Using L<User::Config::UI::HTMLFormHandler> as UI, the form is generated to fit
27 to the options set by the different modules using L<User::Config>. With this
28 model it is possible to let L<HTML::FormHandler> handle the update of the
29 different settings, after the user made them.
30  
31 =head2 METHODS
32  
33 See L<HTML::FormHandler> for more information about C<<$self->update_model()>>
34 and C<<$self->build_item()>>.
35  
36 =cut
37  
38 0 ▶sub _fieldname2obj {
Subroutine _fieldname2obj: not called CC=2 SCAR=17.9
39 0 my ($field) = @_;
40 0 local @_ = split /\./,$field->name;
41 0 ▶ pop if $_[-1] =~ m/^_hfh_/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[-1] =~ /^_hfh_/ 0 0 0
42 0 my $method = pop;
43 0 return join("::"), $method;
44 }
45  
46 0 ▶sub update_model {
Subroutine update_model: not called CC=3 SCAR=24.8
Pod undocumented
47 0 my ($self) = @_;
48 0 for(@{$self->fields}) {
49 0 ▶ next if($_->value eq $_->init_value);
Branch: 1 branch
BranchTrueFalseTotal
if $_->value eq $_->init_value 0 0 0
50 0 my ($object, $method) = _fieldname2obj($_);
51 0 $object->$method($self->{item_class}, $_->value);
52 }
53 }
54  
55 0 ▶sub build_item {
Subroutine build_item: not called CC=2 SCAR=17.9
Pod undocumented
56 0 my ($self) = @_;
57 0 for(@{$self->fields}) {
58 0 my ($object, $method) = _fieldname2obj($_);
59 0 my $val = $object->$method($self->{item_class});
60 0 $_->init_value($val);
61 0 $_->value($val);
62 }
63 }
64  
65 =head1 AUTHOR
66  
67 Benjamin Tietz E<lt>benjamin@micronet24.deE<gt>
68  
69 =head1 COPYRIGHT AND LICENSE
70  
71 Copyright (C) 2011 by Benjamin Tietz
72  
73 This library is free software; you can redistribute it and/or modify
74 it under the same terms as Perl itself, either Perl version 5.10.1 or,
75 at your option, any later version of Perl 5 you may have available.
76  
77 =cut
78  
79 1 1;
80  
« HTMLFormHandler.pm ↑ Summary