| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package meon::Web::Role::Form; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
7908614
|
use Moose::Role; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Carp 'croak'; |
|
5
|
|
|
|
|
|
|
use meon::Web::Util; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'c' => ( is => 'ro', isa => 'Object', required => 1 ); |
|
8
|
|
|
|
|
|
|
has 'config' => ( is => 'ro', isa => 'Object', lazy_build => 1 ); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub _build_config { |
|
11
|
|
|
|
|
|
|
my ($self) = @_; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $c = $self->c; |
|
14
|
|
|
|
|
|
|
my $dom = $c->model('ResponseXML')->dom; |
|
15
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
|
16
|
|
|
|
|
|
|
my ($form_config) = $xpc->findnodes('/w:page/w:meta/w:form',$dom); |
|
17
|
|
|
|
|
|
|
return $form_config; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
around 'submitted' => sub { |
|
21
|
|
|
|
|
|
|
my ($orig,$self) = @_; |
|
22
|
|
|
|
|
|
|
return unless $self->is_valid; |
|
23
|
|
|
|
|
|
|
$self->$orig(@_); |
|
24
|
|
|
|
|
|
|
}; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub get_config_text { |
|
27
|
|
|
|
|
|
|
my ($self, $el_name) = @_; |
|
28
|
|
|
|
|
|
|
croak 'need element name argument' |
|
29
|
|
|
|
|
|
|
unless defined $el_name && length($el_name); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
|
32
|
|
|
|
|
|
|
my $form_config = $self->config; |
|
33
|
|
|
|
|
|
|
my ($text) = map { $_->textContent } $xpc->findnodes('w:'.$el_name,$form_config); |
|
34
|
|
|
|
|
|
|
die 'config element '.$el_name.' not found' |
|
35
|
|
|
|
|
|
|
unless defined $text; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return $text; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub set_config_text { |
|
41
|
|
|
|
|
|
|
my ($self, $el_name, $value) = @_; |
|
42
|
|
|
|
|
|
|
croak 'need element name argument' |
|
43
|
|
|
|
|
|
|
unless defined $el_name && length($el_name); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
|
46
|
|
|
|
|
|
|
my $form_config = $self->config; |
|
47
|
|
|
|
|
|
|
my ($config_el) = $xpc->findnodes('w:'.$el_name,$form_config); |
|
48
|
|
|
|
|
|
|
if (defined($value)) { |
|
49
|
|
|
|
|
|
|
unless ($config_el) { |
|
50
|
|
|
|
|
|
|
$form_config->appendText(q{ }x4); |
|
51
|
|
|
|
|
|
|
$config_el = $form_config->addNewChild($form_config->namespaceURI,$el_name); |
|
52
|
|
|
|
|
|
|
$form_config->appendText("\n".q{ }x4); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
$config_el->removeChildNodes(); |
|
55
|
|
|
|
|
|
|
$config_el->appendText($value); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
else { |
|
58
|
|
|
|
|
|
|
# FIXME remove whitespaces textnodes before |
|
59
|
|
|
|
|
|
|
$form_config->removeChild($config_el) |
|
60
|
|
|
|
|
|
|
if defined $config_el; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return $config_el; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_config_folder { |
|
67
|
|
|
|
|
|
|
my ($self, $el_name) = @_; |
|
68
|
|
|
|
|
|
|
my $c = $self->c; |
|
69
|
|
|
|
|
|
|
my $path = $self->get_config_text($el_name); |
|
70
|
|
|
|
|
|
|
$path = meon::Web::Util->path_fixup($path); |
|
71
|
|
|
|
|
|
|
$path = $c->stash->{xml_file}->dir->subdir($path); |
|
72
|
|
|
|
|
|
|
return $path; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub detach { |
|
76
|
|
|
|
|
|
|
my ($self,$detach_path) = @_; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $c = $self->c; |
|
79
|
|
|
|
|
|
|
my $detach_uri = ( |
|
80
|
|
|
|
|
|
|
$detach_path |
|
81
|
|
|
|
|
|
|
? $c->traverse_uri($detach_path) |
|
82
|
|
|
|
|
|
|
: $c->req->uri->absolute |
|
83
|
|
|
|
|
|
|
); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$c->session->{post_redirect_path} = $detach_uri; |
|
86
|
|
|
|
|
|
|
$c->res->redirect($c->req->uri->absolute); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub redirect { |
|
90
|
|
|
|
|
|
|
my ($self,$redirect) = @_; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $c = $self->c; |
|
93
|
|
|
|
|
|
|
my $redirect_uri = $c->traverse_uri($redirect); |
|
94
|
|
|
|
|
|
|
$redirect_uri = $redirect_uri->absolute |
|
95
|
|
|
|
|
|
|
if $redirect_uri->can('absolute'); |
|
96
|
|
|
|
|
|
|
$c->res->redirect($redirect_uri); |
|
97
|
|
|
|
|
|
|
$c->detach; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub store_config { |
|
101
|
|
|
|
|
|
|
my $self = shift; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
|
104
|
|
|
|
|
|
|
my $filename = meon::Web::env->xml_file; |
|
105
|
|
|
|
|
|
|
my $dom = XML::LibXML->load_xml(location => $filename); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my ($form_config) = $xpc->findnodes('/w:page/w:meta/w:form',$dom); |
|
108
|
|
|
|
|
|
|
$form_config->replaceNode($self->config); |
|
109
|
|
|
|
|
|
|
return IO::Any->spew( |
|
110
|
|
|
|
|
|
|
[$filename], |
|
111
|
|
|
|
|
|
|
$dom->toString, |
|
112
|
|
|
|
|
|
|
{atomic => 1}, |
|
113
|
|
|
|
|
|
|
); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |