| 1 | package HTML::FormHandler::Widget::ApplyRole; | ||||||||||
| 2 | # ABSTRACT: role to apply widgets | ||||||||||
| 3 | 149 | $HTML::FormHandler::Widget::ApplyRole::VERSION = '0.410002'; | |||||||||
| 4 | 149 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 149 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 149 | ▶ | use Class::MOP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 149 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 149 | ▶ | use Class::Load qw/ load_optional_class /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 149 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 149 | our $ERROR; | |||||||||
| 12 | |||||||||||
| 13 | 3 | ▶ | sub apply_widget_role { | ||||||||
|
Subroutine
apply_widget_role: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 14 | 3 | my ( $self, $target, $widget_name, $dir ) = @_; | |||||||||
| 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 | 2844 | ▶ | sub get_widget_role { | ||||||||
|
Subroutine
get_widget_role: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||
| 21 | 2844 | my ( $self, $widget_name, $dir ) = @_; | |||||||||
| 22 | 2844 | my $widget_class = $self->widget_class($widget_name); | |||||||||
| 23 | 2844 | ▶ | my $ldir = $dir ? '::' . $dir . '::' : '::'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | |||||||||||
| 25 | 2844 | my $widget_ns = $self->widget_name_space; | |||||||||
| 26 | 2844 | my @name_spaces = @$widget_ns; | |||||||||
| 27 | 2844 | push @name_spaces, ('HTML::FormHandler::Widget', 'HTML::FormHandlerX::Widget'); | |||||||||
| 28 | 2844 | my @classes; | |||||||||
| 29 | 2844 | ▶ | if ( $widget_class =~ s/^\+// ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | { | ||||||||||
| 31 | 2 | push @classes, $widget_class; | |||||||||
| 32 | } | ||||||||||
| 33 | 2844 | foreach my $ns (@name_spaces) { | |||||||||
| 34 | 5721 | push @classes, $ns . $ldir . $widget_class; | |||||||||
| 35 | } | ||||||||||
| 36 | 2844 | foreach my $try (@classes) { | |||||||||
| 37 | 2874 | ▶ | 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 | 2844 | ▶ | sub widget_class { | ||||||||
|
Subroutine
widget_class: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 45 | 2844 | my ( $self, $widget ) = @_; | |||||||||
| 46 | 2844 | ▶ | return unless $widget; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 2844 | ▶ | 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 | 2844 | return $widget; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 149 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 149 | 1; | |||||||||
| 56 | |||||||||||
| 57 | __END__ | ||||||||||