| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | App::LinkSite::Social | ||||||||||
| 4 | |||||||||||
| 5 | =head1 SYNOPIS | ||||||||||
| 6 | |||||||||||
| 7 | (You probably want to just look at the L<linksite> application.) | ||||||||||
| 8 | |||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||
| 10 | |||||||||||
| 11 | A class to model a social link on a link site (part of App::LinkSite). | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | 2 | ▶ | use Feature::Compat::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 2 | class App::LinkSite::Social { | |||||||||
| 18 | 2 | our $VERSION = '0.1.3'; | |||||||||
| 19 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | ▶ | use feature qw[say signatures]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | ▶ | no if $] >= 5.038, 'warnings', qw[experimental::signatures experimental::class]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 2 | field $service :reader :param; | |||||||||
| 25 | 2 | field $handle :reader :param; | |||||||||
| 26 | 2 | field $url :reader :param = undef; | |||||||||
| 27 | |||||||||||
| 28 | # TODO: This needs to be a class field. | ||||||||||
| 29 | field $urls = { | ||||||||||
| 30 | facebook => { | ||||||||||
| 31 | url => "https://facebook.com/", | ||||||||||
| 32 | name => 'Facebook', | ||||||||||
| 33 | }, | ||||||||||
| 34 | 'x-twitter' => { | ||||||||||
| 35 | # This is currently still the correct URL | ||||||||||
| 36 | url => "https://twitter.com/", | ||||||||||
| 37 | name => 'X/Twitter', | ||||||||||
| 38 | }, | ||||||||||
| 39 | instagram => { | ||||||||||
| 40 | url => "https://instagram.com/", | ||||||||||
| 41 | name => 'Instagram', | ||||||||||
| 42 | }, | ||||||||||
| 43 | tiktok => { | ||||||||||
| 44 | url => "https://tiktok.com/@", | ||||||||||
| 45 | name => 'TikTok', | ||||||||||
| 46 | }, | ||||||||||
| 47 | linkedin => { | ||||||||||
| 48 | url => "https://linkedin.com/in/", | ||||||||||
| 49 | name => 'LinkedIn', | ||||||||||
| 50 | }, | ||||||||||
| 51 | substack => { | ||||||||||
| 52 | url => "https://XXXX.substack.com/", | ||||||||||
| 53 | name => 'Substack', | ||||||||||
| 54 | }, | ||||||||||
| 55 | github => { | ||||||||||
| 56 | url => "https://github.com/", | ||||||||||
| 57 | name => 'GitHub', | ||||||||||
| 58 | }, | ||||||||||
| 59 | medium => { | ||||||||||
| 60 | url => "https://XXXX.medium.com/", | ||||||||||
| 61 | name => 'Medium', | ||||||||||
| 62 | }, | ||||||||||
| 63 | reddit => { | ||||||||||
| 64 | url => "https://reddit.com/user/", | ||||||||||
| 65 | name => 'Reddit', | ||||||||||
| 66 | }, | ||||||||||
| 67 | quora => { | ||||||||||
| 68 | url => "https://quora.com/profile/", | ||||||||||
| 69 | name => 'Quora', | ||||||||||
| 70 | }, | ||||||||||
| 71 | mastodon => { | ||||||||||
| 72 | # Hmm... | ||||||||||
| 73 | url => "https://fosstodon.org/@", | ||||||||||
| 74 | name => 'Mastodon', | ||||||||||
| 75 | }, | ||||||||||
| 76 | threads => { | ||||||||||
| 77 | url => "https://www.threads.net/@", | ||||||||||
| 78 | name => 'Threads', | ||||||||||
| 79 | }, | ||||||||||
| 80 | bluesky => { | ||||||||||
| 81 | url => 'https://bsky.app/profile/', | ||||||||||
| 82 | name => 'Bluesky', | ||||||||||
| 83 | }, | ||||||||||
| 84 | letterboxd => { | ||||||||||
| 85 | url => 'https://letterboxd.com/', | ||||||||||
| 86 | name => 'Letterboxd', | ||||||||||
| 87 | }, | ||||||||||
| 88 | lastfm => { | ||||||||||
| 89 | url => 'https://last.fm/user/', | ||||||||||
| 90 | name => 'last.fm', | ||||||||||
| 91 | }, | ||||||||||
| 92 | 'ko-fi' => { | ||||||||||
| 93 | url => 'https://ko-fi.com/', | ||||||||||
| 94 | name => 'Ko-fi', | ||||||||||
| 95 | } | ||||||||||
| 96 | 2 | }; | |||||||||
| 97 | |||||||||||
| 98 | =head1 METHODS | ||||||||||
| 99 | |||||||||||
| 100 | =head2 mk_social_link | ||||||||||
| 101 | |||||||||||
| 102 | Return a fragment of HTML that is used to represent this social media link | ||||||||||
| 103 | on the link site. | ||||||||||
| 104 | |||||||||||
| 105 | =cut | ||||||||||
| 106 | |||||||||||
| 107 | 0 | ▶ | method mk_social_link { | ||||||||
|
Subroutine
mk_social_link: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 108 | 0 | ▶ | return $url if $url; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | |||||||||||
| 110 | 0 | my $social_url; | |||||||||
| 111 | |||||||||||
| 112 | 0 | ▶ | if (exists $urls->{$service}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 0 | $social_url = $urls->{$service}{url}; | |||||||||
| 114 | } else { | ||||||||||
| 115 | 0 | warn('Unknown social service: ', $service); | |||||||||
| 116 | 0 | return; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 0 | ▶ | if ($social_url =~ /XXXX/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | 0 | $social_url =~ s/XXXX/$handle/g; | |||||||||
| 121 | } else { | ||||||||||
| 122 | 0 | $social_url .= $handle; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 0 | return $social_url; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | |||||||||||
| 129 | =head2 social_icon_template | ||||||||||
| 130 | |||||||||||
| 131 | Return a string that is used to produce the HTML that displays the social | ||||||||||
| 132 | icon and link on the link site. The template string will expect three | ||||||||||
| 133 | substitution values: | ||||||||||
| 134 | |||||||||||
| 135 | =over 4 | ||||||||||
| 136 | |||||||||||
| 137 | =item * | ||||||||||
| 138 | |||||||||||
| 139 | The title for the link (probably the `name` from the `$urls` field) | ||||||||||
| 140 | |||||||||||
| 141 | =item * | ||||||||||
| 142 | |||||||||||
| 143 | The link for the social account (as built by `mk_social_link()`) | ||||||||||
| 144 | |||||||||||
| 145 | =item * | ||||||||||
| 146 | |||||||||||
| 147 | The name of the social media site's icon as represented in Font Awesome | ||||||||||
| 148 | (probably a key from the `$urls` field). | ||||||||||
| 149 | |||||||||||
| 150 | =back | ||||||||||
| 151 | |||||||||||
| 152 | =cut | ||||||||||
| 153 | |||||||||||
| 154 | 0 | ▶ | method social_icon_template { | ||||||||
|
Subroutine
social_icon_template: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 155 | 0 | return q[<a rel='me' title='%s' href='%s'><i class='fa-brands fa-3x fa-%s'></i></a>]; | |||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | =head2 mk_social_icon | ||||||||||
| 159 | |||||||||||
| 160 | Returns a fragment of HTML that will be used to display the social media | ||||||||||
| 161 | account on the web site. | ||||||||||
| 162 | |||||||||||
| 163 | =cut | ||||||||||
| 164 | |||||||||||
| 165 | 0 | ▶ | method mk_social_icon { | ||||||||
|
Subroutine
mk_social_icon: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 166 | return sprintf $self->social_icon_template, | ||||||||||
| 167 | 0 | $urls->{$service}{name}, $self->mk_social_link(), $service; | |||||||||
| 168 | } | ||||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | =head1 AUTHOR | ||||||||||
| 172 | |||||||||||
| 173 | Dave Cross <dave@davecross.co.uk> | ||||||||||
| 174 | |||||||||||
| 175 | =head1 COPYRIGHT AND LICENCE | ||||||||||
| 176 | |||||||||||
| 177 | Copyright (c) 2024, Magnum Solutions Ltd. All Rights Reserved. | ||||||||||
| 178 | |||||||||||
| 179 | This library is free software; you can redistribute it and/or modify it | ||||||||||
| 180 | under the same terms as Perl itself. | ||||||||||
| 181 | |||||||||||
| 182 | =cut | ||||||||||
| 183 | |||||||||||
| 184 | 2 | 1; | |||||||||