| 1 | package Catalyst::Controller::FormBuilder::Action; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use CGI::FormBuilder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use CGI::FormBuilder::Source::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Class::Inspector; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use MRO::Compat; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use base qw/Catalyst::Action Class::Data::Inheritable/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | __PACKAGE__->mk_classdata(qw/_source_class/); | |||||||||||||||||||||||||||
| 14 | 3 | __PACKAGE__->mk_accessors(qw/_attr_params _source_type/); | |||||||||||||||||||||||||||
| 15 | 3 | __PACKAGE__->_source_class('CGI::FormBuilder::Source::File'); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | sub _setup_form { | ||||||||||||||||||||||||||
|
Subroutine
_setup_form: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||
| 18 | 5 | my ( $self, $controller, $c ) = @_; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Load configured defaults from the user, and add in some | ||||||||||||||||||||||||||||
| 21 | # custom settings needed to meld FormBuilder with Catalyst | ||||||||||||||||||||||||||||
| 22 | 5 | ▶ | my $config = $controller->config->{'Controller::FormBuilder'} || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$controller->config->{'Controller::FormBuilder'} || {}
MC/DC0%0/1
$controller->config->{'Controller::FormBuilder'} || {}
$controller->config->{'Controller::FormBuilder'}
Truth table50%1/2
A
A= $controller->config->{'Controller::FormBuilder'}
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | my %attr = ( | ||||||||||||||||||||||||||||
| 25 | debug => $c->debug ? 2 : 0, | ||||||||||||||||||||||||||||
| 26 | 5 | ▶ | %{ $config->{new} || {} }, | ||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'new'} || {}
MC/DC0%0/1
$config->{'new'} || {}
$config->{'new'}
Truth table50%1/2
A
A= $config->{'new'}
| |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | %{ $self->_source_conf_data( $controller, $c ) || {} }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->_source_conf_data($controller, $c) || {}
MC/DC100%1/1
$self->_source_conf_data($controller, $c) || {}
$self->_source_conf_data($controller, $c)
Truth table100%2/2
A
A= $self->_source_conf_data($controller, $c)
| |||||||||||||||||||||||||||||
| 28 | params => $c->req, | ||||||||||||||||||||||||||||
| 29 | action => $c->req->uri->path, | ||||||||||||||||||||||||||||
| 30 | header => 0, # always disable headers | ||||||||||||||||||||||||||||
| 31 | cookies => 0, # and cookies | ||||||||||||||||||||||||||||
| 32 | title => __PACKAGE__, | ||||||||||||||||||||||||||||
| 33 | c => $c, # allow \&validate to get $c, | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 5 | $self->_create_formbuilder(\%attr); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | ▶ | sub _source_conf_data { | ||||||||||||||||||||||||||
|
Subroutine
_source_conf_data: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 40 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 5 | ▶ | if ( my $source = $self->_source(@_) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 4 | ▶ | s/^\.*/./ if $_; # XX workaround for CGI::FormBuilder::Source::File bug | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 4 | my $adapter = $self->_create_source_adapter(); | |||||||||||||||||||||||||||
| 45 | 4 | return { $adapter->parse($source) }; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 5 | ▶ | sub _create_formbuilder { | ||||||||||||||||||||||||||
|
Subroutine
_create_formbuilder: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 5 | return CGI::FormBuilder->new( @_ ); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 4 | ▶ | sub _create_source_adapter { | ||||||||||||||||||||||||||
|
Subroutine
_create_source_adapter: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||
| 56 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 4 | ▶ | my $class = $self->_source_type || $self->_source_class; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->_source_type || $self->_source_class
MC/DC0%0/2
$self->_source_type || $self->_source_class
$self->_source_type
$self->_source_class
Truth table33%1/3
A || B
A= $self->_source_typeB= $self->_source_class
| |||||||||||||||||||||||||||||
| 59 | 4 | ▶ | unless ( Class::Inspector->loaded($class) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | require Class::Inspector->filename($class); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 4 | return $class->new(); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 5 | ▶ | sub _source { | ||||||||||||||||||||||||||
|
Subroutine
_source: called CC=12 SCAR=26.7
| |||||||||||||||||||||||||||||
| 67 | 5 | my ( $self, $controller, $c ) = @_; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 5 | ▶ | my $config = $controller->config->{'Controller::FormBuilder'} || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$controller->config->{'Controller::FormBuilder'} || {}
MC/DC0%0/1
$controller->config->{'Controller::FormBuilder'} || {}
$controller->config->{'Controller::FormBuilder'}
Truth table50%1/2
A
A= $controller->config->{'Controller::FormBuilder'}
| |||||||||||||||||||||||||||||
| 70 | 5 | ▶ | my $name = $self->_attr_params->[0] || $self->reverse; | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->_attr_params->[0] || $self->reverse
MC/DC0%0/2
$self->_attr_params->[0] || $self->reverse
$self->_attr_params->[0]
$self->reverse
Truth table66%2/3
A || B
A= $self->_attr_params->[0]B= $self->reverse
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # remove leading and trailing slashes | ||||||||||||||||||||||||||||
| 73 | 5 | $name =~ s#^/+##; | |||||||||||||||||||||||||||
| 74 | 5 | $name =~ s#/+$##; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 5 | my $fbdir = $self->_form_path($controller, $c); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # Attempt to autoload config and template files | ||||||||||||||||||||||||||||
| 79 | # Cleanup suffix to allow ".fb" or "fb" in config | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 5 | ▶ | my $fbsuf = exists( $config->{form_suffix} ) ? $config->{form_suffix} : 'fb'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 5 | ▶ | $fbsuf =~ s/^\.*/./ if $fbsuf; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 5 | my $fbfile = "$name$fbsuf"; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 5 | ▶ | $c->log->debug("Form ($name): Looking for config file $fbfile") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | if $c->debug; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # Look for files relative to our current action url (/books/edit) | ||||||||||||||||||||||||||||
| 89 | 5 | for my $dir ( @$fbdir ) { | |||||||||||||||||||||||||||
| 90 | 5 | my $conf = File::Spec->catfile( $dir, $fbfile ); | |||||||||||||||||||||||||||
| 91 | 5 | ▶ | if ( -f $conf && -r _ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $conf and -r _
MC/DC50%1/2
-f $conf and -r _
-f $conf
-r _
Truth table66%2/3
A and B
A= -f $confB= -r _
| |||||||||||||||||||||||||||||
| 92 | 4 | ▶ | $c->log->debug("Form ($name): Found form config $conf") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | if $c->debug; | ||||||||||||||||||||||||||||
| 94 | 4 | return $conf; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | my $err = sprintf( "Form (%s): Can't find form config $fbfile in: %s", | |||||||||||||||||||||||||||
| 99 | $name, join( ", ", @$fbdir ) ); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | ▶ | if ( $self->_attr_params->[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $c->log->error($err); | |||||||||||||||||||||||||||
| 103 | 0 | $c->error($err); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | else { | ||||||||||||||||||||||||||||
| 106 | 1 | ▶ | $c->log->debug($err) if $c->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | return; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 5 | ▶ | sub _form_path { | ||||||||||||||||||||||||||
|
Subroutine
_form_path: called CC=4 SCAR=16.4
| |||||||||||||||||||||||||||||
| 113 | 5 | my ( $self, $controller, $c ) = @_; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 5 | ▶ | my $config = $controller->config->{'Controller::FormBuilder'} || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$controller->config->{'Controller::FormBuilder'} || {}
MC/DC0%0/1
$controller->config->{'Controller::FormBuilder'} || {}
$controller->config->{'Controller::FormBuilder'}
Truth table50%1/2
A
A= $controller->config->{'Controller::FormBuilder'}
| |||||||||||||||||||||||||||||
| 116 | 5 | my $fbdir = [ File::Spec->catfile( $c->config->{home}, 'root', 'forms' ) ]; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 5 | ▶ | if ( my $dir = $config->{form_path} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $fbdir = ref $dir ? $dir : [ split /\s*:\s*/, $dir ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 5 | return $fbdir; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 5 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 127 | 5 | my ( $controller, $c ) = @_; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | return $self->maybe::next::method(@_) | ||||||||||||||||||||||||||||
| 130 | unless exists $self->attributes->{ActionClass} | ||||||||||||||||||||||||||||
| 131 | && $self->attributes->{ActionClass}[0] eq | ||||||||||||||||||||||||||||
| 132 | 5 | ▶ | $controller->_fb_setup->{action}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->attributes->{"ActionClass"} and $self->attributes->{"ActionClass"}[0] eq $controller->_fb_setup->{"action"}
MC/DC0%0/2
exists $self->attributes->{"ActionClass"} and $self->attributes->{"ActionClass"}[0] eq $controller->_fb_setup->{"action"}
exists $self->attributes->{"ActionClass"}
$self->attributes->{"ActionClass"}[0] eq $controller->_fb_setup->{"action"}
Truth table33%1/3
A and B
A= exists $self->attributes->{"ActionClass"}B= $self->attributes->{"ActionClass"}[0] eq $controller->_fb_setup->{"action"}
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 5 | my $form = $self->_setup_form(@_); | |||||||||||||||||||||||||||
| 135 | 5 | Scalar::Util::weaken($form->{c}); | |||||||||||||||||||||||||||
| 136 | 5 | $controller->_formbuilder($form); | |||||||||||||||||||||||||||
| 137 | 5 | $self->maybe::next::method(@_); | |||||||||||||||||||||||||||
| 138 | 5 | $controller->_formbuilder($form); # keep the same form in case of forwards | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 5 | $self->setup_template_vars( @_ ); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 3 | 1; | |||||||||||||||||||||||||||