| 1 | package HTML::FormHandler::Widget::ApplyRole; | ||||||||||
| 2 | # ABSTRACT: role to apply widgets | ||||||||||
| 3 | 148 | $HTML::FormHandler::Widget::ApplyRole::VERSION = '0.410001'; | |||||||||
| 4 | 148 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 148 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 148 | ▶ | use Class::MOP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 148 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 148 | ▶ | use Class::Load qw/ load_optional_class /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 148 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 148 | our $ERROR; | |||||||||
| 12 | |||||||||||
| 13 | sub apply_widget_role { | ||||||||||
| 14 | 3 | ▶ | my ( $self, $target, $widget_name, $dir ) = @_; | ||||||||
|
Subroutine
apply_widget_role: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 15 | |||||||||||
| 16 | 3 | my $render_role = $self->get_widget_role( $widget_name, $dir ); | |||||||||
| 17 | 3 | ▶ | $render_role->meta->apply($target) if $render_role; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | sub get_widget_role { | ||||||||||
| 21 | 2834 | ▶ | my ( $self, $widget_name, $dir ) = @_; | ||||||||
|
Subroutine
get_widget_role: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||
| 22 | 2834 | my $widget_class = $self->widget_class($widget_name); | |||||||||
| 23 | 2834 | ▶ | my $ldir = $dir ? '::' . $dir . '::' : '::'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | |||||||||||
| 25 | 2834 | my $widget_ns = $self->widget_name_space; | |||||||||
| 26 | 2834 | my @name_spaces = @$widget_ns; | |||||||||
| 27 | 2834 | push @name_spaces, ('HTML::FormHandler::Widget', 'HTML::FormHandlerX::Widget'); | |||||||||
| 28 | 2834 | my @classes; | |||||||||
| 29 | 2834 | ▶ | if ( $widget_class =~ s/^\+// ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | { | ||||||||||
| 31 | 2 | push @classes, $widget_class; | |||||||||
| 32 | } | ||||||||||
| 33 | 2834 | foreach my $ns (@name_spaces) { | |||||||||
| 34 | 5701 | push @classes, $ns . $ldir . $widget_class; | |||||||||
| 35 | } | ||||||||||
| 36 | 2834 | foreach my $try (@classes) { | |||||||||
| 37 | 2864 | ▶ | return $try if load_optional_class($try); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | } | ||||||||||
| 39 | 2 | die "Can't find $dir widget $widget_class from " . join(", ", @name_spaces); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | # this is for compatibility with widget names like 'radio_group' | ||||||||||
| 43 | # RadioGroup, Textarea, etc. also work | ||||||||||
| 44 | sub widget_class { | ||||||||||
| 45 | 2834 | ▶ | my ( $self, $widget ) = @_; | ||||||||
|
Subroutine
widget_class: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 46 | 2834 | ▶ | return unless $widget; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 2834 | ▶ | if($widget eq lc $widget) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 3 | $widget =~ s/^(\w{1})/\u$1/g; | |||||||||
| 49 | 3 | $widget =~ s/_(\w{1})/\u$1/g; | |||||||||
| 50 | } | ||||||||||
| 51 | 2834 | return $widget; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 148 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 148 | 1; | |||||||||
| 56 | |||||||||||
| 57 | __END__ | ||||||||||
| 58 | |||||||||||
| 59 | =pod | ||||||||||
| 60 | |||||||||||
| 61 | =encoding UTF-8 | ||||||||||
| 62 | |||||||||||
| 63 | =head1 NAME | ||||||||||
| 64 | |||||||||||
| 65 | HTML::FormHandler::Widget::ApplyRole - role to apply widgets | ||||||||||
| 66 | |||||||||||
| 67 | =head1 VERSION | ||||||||||
| 68 | |||||||||||
| 69 | version 0.410001 | ||||||||||
| 70 | |||||||||||
| 71 | =head1 AUTHOR | ||||||||||
| 72 | |||||||||||
| 73 | FormHandler Contributors - see HTML::FormHandler | ||||||||||
| 74 | |||||||||||
| 75 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 76 | |||||||||||
| 77 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||
| 78 | |||||||||||
| 79 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 80 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 81 | |||||||||||
| 82 | =cut | ||||||||||