| 1 | package Catalyst::Model::FormFu; | ||||||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | $Catalyst::Model::FormFu::VERSION = '0.004'; | |||||||||||||
| 4 | } | ||||||||||||||
| 5 | |||||||||||||||
| 6 | # ABSTRACT: Speedier interface to HTML::FormFu for Catalyst | ||||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 2 | ▶ | use HTML::FormFu; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 2 | ▶ | use HTML::FormFu::Library; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 2 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 2 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 2 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 2 | extends 'Catalyst::Model'; | |||||||||||||
| 17 | 2 | with 'Catalyst::Component::InstancePerContext'; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 2 | has model_stash => ( is => 'ro', isa => 'HashRef' ); | |||||||||||||
| 20 | 0 | ▶ | has constructor => ( is => 'ro', isa => 'HashRef', default => sub { {} } ); | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||
| 21 | 2 | has context_stash => ( is => 'ro', isa => 'Str', default => 'context' ); | |||||||||||||
| 22 | 2 | has config_callback => ( is => 'ro', isa => 'Bool', default => 1 ); | |||||||||||||
| 23 | 2 | has forms => ( is => 'ro', isa => 'HashRef' ); | |||||||||||||
| 24 | 2 | has cache => ( is => 'ro', isa => 'HashRef', builder => '_build_cache' ); | |||||||||||||
| 25 | 2 | has languages_from_context => ( is => 'ro', isa => 'Bool', default => 0 ); | |||||||||||||
| 26 | 2 | has localize_from_context => ( is => 'ro', isa => 'Bool', default => 0 ); | |||||||||||||
| 27 | 2 | has default_action_use_name => ( is => 'ro', isa => 'Bool', default => 0 ); | |||||||||||||
| 28 | 2 | has default_action_use_path => ( is => 'ro', isa => 'Bool', default => 0 ); | |||||||||||||
| 29 | |||||||||||||||
| 30 | |||||||||||||||
| 31 | sub _build_cache | ||||||||||||||
| 32 | 1 | ▶ | { | ||||||||||||
|
Subroutine
_build_cache: called CC=2 SCAR=11.6
| |||||||||||||||
| 33 | 1 | my $self = shift; | |||||||||||||
| 34 | |||||||||||||||
| 35 | 1 | my %cache; | |||||||||||||
| 36 | |||||||||||||||
| 37 | 1 | ▶ | while ( my ($id, $config_file) = each %{$self->forms} ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | { | ||||||||||||||
| 39 | 0 | my %args = ( query_type => 'Catalyst', %{$self->constructor} ); | |||||||||||||
| 40 | 0 | my $form = HTML::FormFu->new(\%args); | |||||||||||||
| 41 | 0 | $form->load_config_file($config_file); | |||||||||||||
| 42 | 0 | $cache{$id} = $form; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | return \%cache; | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 0 | ▶ | sub build_per_context_instance { | ||||||||||||
|
Subroutine
build_per_context_instance: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | my ($self, $c) = @_; | |||||||||||||
| 51 | |||||||||||||||
| 52 | 0 | my %args; | |||||||||||||
| 53 | |||||||||||||||
| 54 | # cache and query | ||||||||||||||
| 55 | 0 | $args{cache} = $self->cache; | |||||||||||||
| 56 | 0 | $args{query} = $c->request; | |||||||||||||
| 57 | |||||||||||||||
| 58 | ### stash | ||||||||||||||
| 59 | 0 | $args{stash}{$self->context_stash} = $c; | |||||||||||||
| 60 | 0 | weaken $args{stash}{$self->context_stash}; | |||||||||||||
| 61 | 0 | ▶ | $args{stash}{schema} = $c->model($self->model_stash->{schema}) if $self->model_stash; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | |||||||||||||||
| 63 | ### config_callback | ||||||||||||||
| 64 | $args{config_callback}{plain_value} = sub | ||||||||||||||
| 65 | 0 | ▶ | { | ||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||
| 66 | 0 | ▶ | return unless defined $_; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | ▶ | if ( /__uri_for\(/ ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | { | ||||||||||||||
| 70 | 0 | s{__uri_for\((.+?)\)__} | |||||||||||||
| 71 | 0 | { $c->uri_for( split( '\s*,\s*', $1 ) ) }eg | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 0 | ▶ | if ( /__path_to\(/ ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | { | ||||||||||||||
| 76 | 0 | s{__path_to\(\s*(.+?)\s*\)__} | |||||||||||||
| 77 | 0 | { $c->path_to( split( '\s*,\s*', $1 ) ) }eg | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | ▶ | if ( /__config\(/ ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 81 | { | ||||||||||||||
| 82 | 0 | s{__config\((.+?)\)__} | |||||||||||||
| 83 | 0 | { $c->config->{$1} }eg | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | 0 | ▶ | } if $self->config_callback; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 86 | |||||||||||||||
| 87 | ### action | ||||||||||||||
| 88 | 0 | ▶ | if ($self->default_action_use_name) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 89 | { | ||||||||||||||
| 90 | 0 | $args{action} = $c->uri_for($c->{action}->name); | |||||||||||||
| 91 | |||||||||||||||
| 92 | 0 | ▶ | $c->log->debug("FormFu - Setting default action by name: $args{action}") | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 93 | if $c->debug; | ||||||||||||||
| 94 | } | ||||||||||||||
| 95 | elsif ($self->default_action_use_path) | ||||||||||||||
| 96 | { | ||||||||||||||
| 97 | 0 | $args{action} = $c->request->base . $c->request->path; | |||||||||||||
| 98 | |||||||||||||||
| 99 | 0 | ▶ | $c->log->debug("FormFu - Setting default action by path: $args{action}") | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 100 | if $c->debug; | ||||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | ### languages | ||||||||||||||
| 104 | 0 | ▶ | $args{languages} = $c->languages if $self->languages_from_context; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | |||||||||||||||
| 106 | ### localize_object | ||||||||||||||
| 107 | 0 | ▶ | $args{add_localize_object} = $c if $self->localize_from_context; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 108 | |||||||||||||||
| 109 | 0 | return HTML::FormFu::Library->new(%args); | |||||||||||||
| 110 | } | ||||||||||||||
| 111 | |||||||||||||||
| 112 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 113 | |||||||||||||||
| 114 | |||||||||||||||
| 115 | __END__ | ||||||||||||||