| 1 | package Statocles::Link; | ||||||||||||||||||||||||||||
| 2 | 101 | our $VERSION = '0.099'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: A link object to build <a> and <link> tags | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 101 | ▶ | use Statocles::Base 'Class'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 101 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | #pod =attr href | ||||||||||||||||||||||||||||
| 9 | #pod | ||||||||||||||||||||||||||||
| 10 | #pod The URL location being linked to. Sets the C<href> attribute. | ||||||||||||||||||||||||||||
| 11 | #pod | ||||||||||||||||||||||||||||
| 12 | #pod =cut | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | has href => ( | ||||||||||||||||||||||||||||
| 15 | is => 'rw', | ||||||||||||||||||||||||||||
| 16 | isa => Str, | ||||||||||||||||||||||||||||
| 17 | required => 1, | ||||||||||||||||||||||||||||
| 18 | 144 | ▶ | coerce => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 19 | 144 | my ( $href ) = @_; | |||||||||||||||||||||||||||
| 20 | 144 | ▶ | if ( blessed $href && $href->isa( 'Mojo::Path' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($href) and $href->isa("Mojo::Path")
MC/DC50%1/2
builtin::blessed($href) and $href->isa("Mojo::Path")
builtin::blessed($href)
$href->isa("Mojo::Path")
Truth table66%2/3
A and B
A= builtin::blessed($href)B= $href->isa("Mojo::Path")
| |||||||||||||||||||||||||||||
| 21 | 3 | return $href->to_abs_string; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | 141 | return $href; | |||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||
| 25 | 101 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | #pod =attr text | ||||||||||||||||||||||||||||
| 28 | #pod | ||||||||||||||||||||||||||||
| 29 | #pod The text inside the link tag. Only useful for <a> links. | ||||||||||||||||||||||||||||
| 30 | #pod | ||||||||||||||||||||||||||||
| 31 | #pod =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | has text => ( | ||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||
| 35 | isa => Maybe[Str], | ||||||||||||||||||||||||||||
| 36 | lazy => 1, | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 38 | # For ease of transition, let's default to title, which we used for the | ||||||||||||||||||||||||||||
| 39 | # text prior to this class. | ||||||||||||||||||||||||||||
| 40 | 0 | return $_[0]->title; | |||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||
| 42 | 101 | ); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | #pod =attr title | ||||||||||||||||||||||||||||
| 45 | #pod | ||||||||||||||||||||||||||||
| 46 | #pod The title of the link. Sets the C<title> attribute. | ||||||||||||||||||||||||||||
| 47 | #pod | ||||||||||||||||||||||||||||
| 48 | #pod =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 101 | has title => ( | |||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||
| 52 | isa => Str, | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | #pod =attr rel | ||||||||||||||||||||||||||||
| 56 | #pod | ||||||||||||||||||||||||||||
| 57 | #pod The relationship of the link. Sets the C<rel> attribute. | ||||||||||||||||||||||||||||
| 58 | #pod | ||||||||||||||||||||||||||||
| 59 | #pod =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 101 | has rel => ( | |||||||||||||||||||||||||||
| 62 | is => 'ro', | ||||||||||||||||||||||||||||
| 63 | isa => Str, | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | #pod =attr type | ||||||||||||||||||||||||||||
| 67 | #pod | ||||||||||||||||||||||||||||
| 68 | #pod The MIME type of the resource being linked to. Sets the C<type> attribute for C<link> | ||||||||||||||||||||||||||||
| 69 | #pod tags. | ||||||||||||||||||||||||||||
| 70 | #pod | ||||||||||||||||||||||||||||
| 71 | #pod =cut | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 101 | has type => ( | |||||||||||||||||||||||||||
| 74 | is => 'ro', | ||||||||||||||||||||||||||||
| 75 | isa => Str, | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | #pod =method new_from_element | ||||||||||||||||||||||||||||
| 79 | #pod | ||||||||||||||||||||||||||||
| 80 | #pod my $link = Statocles::Link->new_from_element( $dom_elem ); | ||||||||||||||||||||||||||||
| 81 | #pod | ||||||||||||||||||||||||||||
| 82 | #pod Construct a new Statocles::Link out of a Mojo::DOM element (either an <a> or a <link>). | ||||||||||||||||||||||||||||
| 83 | #pod | ||||||||||||||||||||||||||||
| 84 | #pod =cut | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | ▶ | sub new_from_element { | ||||||||||||||||||||||||||
|
Subroutine
new_from_element: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 2 | my ( $class, $elem ) = @_; | |||||||||||||||||||||||||||
| 88 | return $class->new( | ||||||||||||||||||||||||||||
| 89 | 2 | ( map {; $_ => $elem->attr( $_ ) } grep { $elem->attr( $_ ) } qw( href title rel ) ), | |||||||||||||||||||||||||||
| 90 | 2 | ( map {; $_ => $elem->$_ } qw( text ) ), | |||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 101 | 1; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||