| 1 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package HTML::Widget::Plugin; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: base class for HTML widgets | ||||||||||||||||||||||||||||
| 5 | 15 | $HTML::Widget::Plugin::VERSION = '0.204'; | |||||||||||||||||||||||||||
| 6 | 15 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use List::MoreUtils qw(uniq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use MRO::Compat; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 15 | ▶ | use Sub::Install; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 13 | #pod | ||||||||||||||||||||||||||||
| 14 | #pod This class provides a simple way to write plugins for HTML::Widget::Factory. | ||||||||||||||||||||||||||||
| 15 | #pod | ||||||||||||||||||||||||||||
| 16 | #pod =head1 METHODS | ||||||||||||||||||||||||||||
| 17 | #pod | ||||||||||||||||||||||||||||
| 18 | #pod =head2 new | ||||||||||||||||||||||||||||
| 19 | #pod | ||||||||||||||||||||||||||||
| 20 | #pod my $plugin = Plugin->new( \%arg ); | ||||||||||||||||||||||||||||
| 21 | #pod | ||||||||||||||||||||||||||||
| 22 | #pod The default plugin constructor is really simple. It requires that the argument | ||||||||||||||||||||||||||||
| 23 | #pod is either a hashref or not given. | ||||||||||||||||||||||||||||
| 24 | #pod | ||||||||||||||||||||||||||||
| 25 | #pod =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 200 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 200 | my ($class, $arg) = @_; | |||||||||||||||||||||||||||
| 29 | 200 | ▶ | $arg = {} unless defined $arg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 200 | ▶ | Carp::confess("illegal argument to $class->new: $arg") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $arg and builtin::reftype($arg) eq "HASH"
MC/DC0%0/2
ref $arg and builtin::reftype($arg) eq "HASH"
ref $arg
builtin::reftype($arg) eq "HASH"
Truth table33%1/3
A and B
A= ref $argB= builtin::reftype($arg) eq "HASH"
| |||||||||||||||||||||||||||||
| 32 | unless ref $arg and reftype $arg eq 'HASH'; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 200 | my @attribute_args; | |||||||||||||||||||||||||||
| 35 | 200 | for (@{ mro::get_linear_isa($class) }) { | |||||||||||||||||||||||||||
| 36 | 449 | ▶ | next unless $_->can('_attribute_args'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 449 | push @attribute_args, $_->_attribute_args(@_); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 200 | @attribute_args = uniq @attribute_args; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 200 | my @boolean_args; | |||||||||||||||||||||||||||
| 42 | 200 | for ($class, @{ mro::get_linear_isa($class) }) { | |||||||||||||||||||||||||||
| 43 | 649 | ▶ | next unless $_->can('_boolean_args'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 649 | push @boolean_args, $_->_boolean_args(@_); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 200 | @boolean_args = uniq @boolean_args; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 200 | bless { | |||||||||||||||||||||||||||
| 49 | %$arg, | ||||||||||||||||||||||||||||
| 50 | _attribute_args => \@attribute_args, | ||||||||||||||||||||||||||||
| 51 | _boolean_args => \@boolean_args, | ||||||||||||||||||||||||||||
| 52 | }, $class; | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | #pod =head2 rewrite_arg | ||||||||||||||||||||||||||||
| 56 | #pod | ||||||||||||||||||||||||||||
| 57 | #pod $arg = $plugin->rewrite_arg($arg); | ||||||||||||||||||||||||||||
| 58 | #pod | ||||||||||||||||||||||||||||
| 59 | #pod This method returns a reference to a hash of arguments, rewriting the given | ||||||||||||||||||||||||||||
| 60 | #pod hash reference to place arguments that are intended to become element | ||||||||||||||||||||||||||||
| 61 | #pod attributes into the C<attr> parameter. | ||||||||||||||||||||||||||||
| 62 | #pod | ||||||||||||||||||||||||||||
| 63 | #pod It moves attributes listed in the results of the C<attribute_args> method. | ||||||||||||||||||||||||||||
| 64 | #pod | ||||||||||||||||||||||||||||
| 65 | #pod =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 57 | ▶ | sub rewrite_arg { | ||||||||||||||||||||||||||
|
Subroutine
rewrite_arg: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 57 | my ($class, $given_arg) = @_; | |||||||||||||||||||||||||||
| 69 | 57 | ▶ | my $arg = { $given_arg ? %$given_arg : () }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 57 | my %bool = map { $_ => 1 } $class->boolean_args; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 57 | for ($class->attribute_args) { | |||||||||||||||||||||||||||
| 74 | 353 | ▶ | if (exists $arg->{$_}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 82 | $arg->{attr}{$_} = delete $arg->{$_}; | |||||||||||||||||||||||||||
| 76 | 82 | ▶ | $arg->{attr}{$_} = $arg->{attr}{$_} ? $_ : undef if $bool{$_}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 57 | return $arg; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | #pod =head2 C< attribute_args > | ||||||||||||||||||||||||||||
| 84 | #pod | ||||||||||||||||||||||||||||
| 85 | #pod This method returns a list of argument names, the values of which should be | ||||||||||||||||||||||||||||
| 86 | #pod used as HTML element attributes. | ||||||||||||||||||||||||||||
| 87 | #pod | ||||||||||||||||||||||||||||
| 88 | #pod The default implementation climbs the plugin's inheritance tree, calling | ||||||||||||||||||||||||||||
| 89 | #pod C<_attribute_args> and pushing all the results onto a list from which unique | ||||||||||||||||||||||||||||
| 90 | #pod results are then returned. | ||||||||||||||||||||||||||||
| 91 | #pod | ||||||||||||||||||||||||||||
| 92 | #pod =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 57 | ▶ | sub attribute_args { | ||||||||||||||||||||||||||
|
Subroutine
attribute_args: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 57 | my ($self) = shift; | |||||||||||||||||||||||||||
| 96 | 57 | return @{ $self->{_attribute_args} }; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 219 | ▶ | sub _attribute_args { qw(id name class tabindex) } | ||||||||||||||||||||||||||
|
Subroutine
_attribute_args: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | #pod =head2 C< boolean_args > | ||||||||||||||||||||||||||||
| 102 | #pod | ||||||||||||||||||||||||||||
| 103 | #pod This method returns a list of argument names, the values of which should be | ||||||||||||||||||||||||||||
| 104 | #pod treated as booleans. | ||||||||||||||||||||||||||||
| 105 | #pod | ||||||||||||||||||||||||||||
| 106 | #pod The default implementation climbs the plugin's inheritance tree, calling | ||||||||||||||||||||||||||||
| 107 | #pod C<_boolean_args> and pushing all the results onto a list from which unique | ||||||||||||||||||||||||||||
| 108 | #pod results are then returned. | ||||||||||||||||||||||||||||
| 109 | #pod | ||||||||||||||||||||||||||||
| 110 | #pod =cut | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 57 | ▶ | sub boolean_args { | ||||||||||||||||||||||||||
|
Subroutine
boolean_args: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 57 | my ($self) = shift; | |||||||||||||||||||||||||||
| 114 | 57 | return @{ $self->{_boolean_args} }; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 302 | ▶ | sub _boolean_args { () } | ||||||||||||||||||||||||||
|
Subroutine
_boolean_args: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | #pod =head2 C< provided_widgets > | ||||||||||||||||||||||||||||
| 120 | #pod | ||||||||||||||||||||||||||||
| 121 | #pod This method should be implemented by any plugin. It returns a list of method | ||||||||||||||||||||||||||||
| 122 | #pod names which a factor should delegate to this plugin. | ||||||||||||||||||||||||||||
| 123 | #pod | ||||||||||||||||||||||||||||
| 124 | #pod =cut | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub provided_widgets { | ||||||||||||||||||||||||||
|
Subroutine
provided_widgets: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 0 | Carp::croak | |||||||||||||||||||||||||||
| 128 | "something called abstract provided_widgets in HTML::Widget::Plugin"; | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 15 | 1; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||