| 1 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Jifty::Web::Form::Link; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | Jifty::Web::Form::Link - Creates a state-preserving HTML link | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Describes an HTML link that may be AJAX-enabled. Most of the | ||||||||||||||||||||||||||||
| 13 | computation of this comes from L<Jifty::Web::Form::Clickable>, which | ||||||||||||||||||||||||||||
| 14 | generates L<Jifty::Web::Form::Link>s. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use base 'Jifty::Web::Form::Element'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Since we don't inherit from Form::Field, we don't otherwise stringify. | ||||||||||||||||||||||||||||
| 21 | # We need the anonymous sub because otherwise the method of the base class is | ||||||||||||||||||||||||||||
| 22 | # always called, instead of the appropriate overridden method in a possible | ||||||||||||||||||||||||||||
| 23 | # child class. | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | use overload '""' => sub { shift->render }, bool => sub { 1 }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Subroutine
__ANON__: not called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head2 accessors | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | Link adds C<url> and C<escape_label> to the list of possible accessors | ||||||||||||||||||||||||||||
| 29 | and mutators, in addition to those offered by | ||||||||||||||||||||||||||||
| 30 | L<Jifty::Web::Form::Element/accessors>. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub accessors { shift->SUPER::accessors(), qw(url escape_label tooltip target rel); } | ||||||||||||||||||||||||||
|
Subroutine
accessors: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 1 | __PACKAGE__->mk_accessors(qw(url escape_label tooltip target rel)); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head2 new PARAMHASH | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Creates a new L<Jifty::Web::Form::Link> object. Possible arguments to | ||||||||||||||||||||||||||||
| 40 | the C<PARAMHASH> are: | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =over | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item url (optional) | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | The URL of the link; defaults to the current URL. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item tooltip | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Additional information about the link. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =item target | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Target of the link. Mostly useful when specified as "_blank" to open | ||||||||||||||||||||||||||||
| 55 | a new window or as the name of a already existing window. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =item escape_label | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | HTML escape the label and tooltip? Defaults to true | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =item anything from L<Jifty::Web::Form::Element> | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Any parameter which L<Jifty::Web::Form::Element/new> can take. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =back | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =cut | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $args = ref($_[0]) ? $_[0] : {@_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||
| 73 | { url => Jifty->web->request->top_request->path, | ||||||||||||||||||||||||||||
| 74 | label => "Click me!", | ||||||||||||||||||||||||||||
| 75 | tooltip => undef, | ||||||||||||||||||||||||||||
| 76 | escape_label => 1, | ||||||||||||||||||||||||||||
| 77 | class => '', | ||||||||||||||||||||||||||||
| 78 | rel => '', | ||||||||||||||||||||||||||||
| 79 | target => '' }, $args ); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | return $self; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head2 url [URL] | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | Gets or sets the URL that the link links to. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head2 as_string | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | Returns the string of the link, including any necessary javascript. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub as_string { | ||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 0 | my $label = $self->label; | |||||||||||||||||||||||||||
| 99 | 0 | my $web = Jifty->web; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | $label = $web->escape( $label ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | if ( $self->escape_label ); | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my $tooltip = $self->tooltip; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | $tooltip = $web->escape( $tooltip ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tooltip and $self->escape_label
MC/DC0%0/2
defined $tooltip and $self->escape_label
defined $tooltip
$self->escape_label
Truth table0%0/3
A and B
A= defined $tooltipB= $self->escape_label
| |||||||||||||||||||||||||||||
| 105 | if ( defined $tooltip and $self->escape_label ); | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | my $output = ''; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | $output .= (qq(<a)); | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | $output .= (qq( id="@{[$self->id]}")) if $self->id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $output .= (qq( class="@{[$self->class]}")) if $self->class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | $output .= (qq( title="@{[$tooltip]}")) if defined $tooltip; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $output .= (qq( target="@{[$self->target]}")) if $self->target; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $output .= (qq( accesskey="@{[$self->key_binding]}")) if $self->key_binding; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $output .= (qq( rel="@{[$self->rel]}")) if $self->rel; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $output .= (qq( href="@{[$web->escape($self->url)]}")); | |||||||||||||||||||||||||||
| 117 | 0 | $output .= ( $self->javascript() ); | |||||||||||||||||||||||||||
| 118 | 0 | $output .= (qq(>$label</a>)); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | $output .= ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | '<script type="text/javascript">' . | ||||||||||||||||||||||||||||
| 122 | $self->key_binding_javascript. | ||||||||||||||||||||||||||||
| 123 | "</script>") if $self->key_binding; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | return $output; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head2 render | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | Render the string of the link, including any necessary javascript. | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub render { | ||||||||||||||||||||||||||
|
Subroutine
render: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | Jifty->web->out($self->as_string); | |||||||||||||||||||||||||||
| 138 | 0 | return (''); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | 1; | |||||||||||||||||||||||||||