| 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::Link; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: a hyperlink | ||||||||||||||||||||||||||||
| 5 | 15 | $HTML::Widget::Plugin::Link::VERSION = '0.203'; | |||||||||||||||||||||||||||
| 6 | 15 | ▶ | use parent 'HTML::Widget::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | #pod =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 9 | #pod | ||||||||||||||||||||||||||||
| 10 | #pod $widget_factory->link({ | ||||||||||||||||||||||||||||
| 11 | #pod text => "my favorite D&D pages", | ||||||||||||||||||||||||||||
| 12 | #pod href => 'http://rjbs.manxome.org/rubric/entries/tags/dnd', | ||||||||||||||||||||||||||||
| 13 | #pod }); | ||||||||||||||||||||||||||||
| 14 | #pod | ||||||||||||||||||||||||||||
| 15 | #pod ...or... | ||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||
| 17 | #pod $widget_factory->link({ | ||||||||||||||||||||||||||||
| 18 | #pod html => "some <em>great<em> d&d pages", | ||||||||||||||||||||||||||||
| 19 | #pod href => 'http://rjbs.manxome.org/rubric/entries/tags/dnd', | ||||||||||||||||||||||||||||
| 20 | #pod }); | ||||||||||||||||||||||||||||
| 21 | #pod | ||||||||||||||||||||||||||||
| 22 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 23 | #pod | ||||||||||||||||||||||||||||
| 24 | #pod This plugin provides a basic input widget. | ||||||||||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||||||||||
| 26 | #pod =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 15 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 15 | ▶ | use HTML::Element; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | #pod =head1 METHODS | ||||||||||||||||||||||||||||
| 32 | #pod | ||||||||||||||||||||||||||||
| 33 | #pod =head2 C< provided_widgets > | ||||||||||||||||||||||||||||
| 34 | #pod | ||||||||||||||||||||||||||||
| 35 | #pod This plugin provides the following widgets: link | ||||||||||||||||||||||||||||
| 36 | #pod | ||||||||||||||||||||||||||||
| 37 | #pod =cut | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 16 | ▶ | sub provided_widgets { qw(link) } | ||||||||||||||||||||||||||
|
Subroutine
provided_widgets: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | #pod =head2 C< link > | ||||||||||||||||||||||||||||
| 42 | #pod | ||||||||||||||||||||||||||||
| 43 | #pod This method returns a basic text hyperlink. | ||||||||||||||||||||||||||||
| 44 | #pod | ||||||||||||||||||||||||||||
| 45 | #pod In addition to the generic L<HTML::Widget::Plugin> attributes, the following | ||||||||||||||||||||||||||||
| 46 | #pod are valid arguments: | ||||||||||||||||||||||||||||
| 47 | #pod | ||||||||||||||||||||||||||||
| 48 | #pod =over | ||||||||||||||||||||||||||||
| 49 | #pod | ||||||||||||||||||||||||||||
| 50 | #pod =item href | ||||||||||||||||||||||||||||
| 51 | #pod | ||||||||||||||||||||||||||||
| 52 | #pod This is the URI to which the link ... um ... links. If no href is supplied, an | ||||||||||||||||||||||||||||
| 53 | #pod exception is thrown. | ||||||||||||||||||||||||||||
| 54 | #pod | ||||||||||||||||||||||||||||
| 55 | #pod =item html | ||||||||||||||||||||||||||||
| 56 | #pod | ||||||||||||||||||||||||||||
| 57 | #pod =item text | ||||||||||||||||||||||||||||
| 58 | #pod | ||||||||||||||||||||||||||||
| 59 | #pod Either of these may contain the text of created link. If passed as C<html>, it | ||||||||||||||||||||||||||||
| 60 | #pod is not escaped; if passed as C<text>, it is. If no text is supplied, the href | ||||||||||||||||||||||||||||
| 61 | #pod is used. If both options are provided, an exception is thrown. | ||||||||||||||||||||||||||||
| 62 | #pod | ||||||||||||||||||||||||||||
| 63 | #pod =back | ||||||||||||||||||||||||||||
| 64 | #pod | ||||||||||||||||||||||||||||
| 65 | #pod =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 16 | ▶ | sub _attribute_args { qw(href title) } | ||||||||||||||||||||||||||
|
Subroutine
_attribute_args: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub link { ## no critic Builtin | ||||||||||||||||||||||||||||
| 70 | 6 | ▶ | my ($self, $factory, $arg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
link: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 6 | ▶ | $arg->{attr}{name} = $arg->{attr}{id} if not defined $arg->{attr}{name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Carp::croak "can't create a link without an href" | ||||||||||||||||||||||||||||
| 75 | 6 | ▶ | unless $arg->{attr}{href}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Carp::croak "text and html arguments for link widget are mutually exclusive" | ||||||||||||||||||||||||||||
| 78 | 5 | ▶ | if $arg->{text} and $arg->{html}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$arg->{"text"} and $arg->{"html"}
MC/DC100%2/2
$arg->{"text"} and $arg->{"html"}
$arg->{"text"}
$arg->{"html"}
Truth table100%3/3
A and B
A= $arg->{"text"}B= $arg->{"html"}
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 4 | my $widget = HTML::Element->new('a'); | |||||||||||||||||||||||||||
| 81 | 4 | $widget->attr($_ => $arg->{attr}{$_}) for keys %{ $arg->{attr} }; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 4 | my $content; | |||||||||||||||||||||||||||
| 84 | 4 | ▶ | if ($arg->{html}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | $content = ref $arg->{html} | ||||||||||||||||||||||||||||
| 86 | ? $arg->{html} | ||||||||||||||||||||||||||||
| 87 | 2 | ▶ | : HTML::Element->new('~literal' => text => $arg->{html}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||
| 89 | 2 | ▶ | $content = defined $arg->{text} ? $arg->{text} : $arg->{attr}{href}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 4 | $widget->push_content($content); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # We chomp this to avoid significant whitespace. -- rjbs, 2008-09-22 | ||||||||||||||||||||||||||||
| 95 | 4 | my $xml = $widget->as_XML; | |||||||||||||||||||||||||||
| 96 | 4 | chomp $xml; | |||||||||||||||||||||||||||
| 97 | 4 | return $xml; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 15 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||