File Coverage

blib/lib/App/LinkSite/Social.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             App::LinkSite::Social
4              
5             =head1 SYNOPIS
6              
7             (You probably want to just look at the L 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     2   144575 use Feature::Compat::Class;
  2         602  
  2         8  
16              
17             class App::LinkSite::Social {
18             our $VERSION = '0.1.1';
19 2     2   488 use strict;
  2         5  
  2         58  
20 2     2   9 use warnings;
  2         4  
  2         77  
21 2     2   9 use feature qw[say signatures];
  2         3  
  2         102  
22 2     2   9 no if $] >= 5.038, 'warnings', qw[experimental::signatures experimental::class];
  2         3  
  2         1587  
23              
24             field $service :reader :param;
25             field $handle :reader :param;
26             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             };
93              
94             =head1 METHODS
95              
96             =head2 mk_social_link
97              
98             Return a fragment of HTML that is used to represent this social media link
99             on the link site.
100              
101             =cut
102              
103             method mk_social_link {
104             return $url if $url;
105              
106             my $social_url;
107              
108             if (exists $urls->{$service}) {
109             $social_url = $urls->{$service}{url};
110             } else {
111             warn('Unknown social service: ', $service);
112             return;
113             }
114              
115             if ($social_url =~ /XXXX/) {
116             $social_url =~ s/XXXX/$handle/g;
117             } else {
118             $social_url .= $handle;
119             }
120              
121             return $social_url;
122             }
123              
124              
125             =head2 social_icon_template
126              
127             Return a string that is used to produce the HTML that displays the social
128             icon and link on the link site. The template string will expect three
129             substitution values:
130              
131             =over 4
132              
133             =item *
134              
135             The title for the link (probably the `name` from the `$urls` field)
136              
137             =item *
138              
139             The link for the social account (as built by `mk_social_link()`)
140              
141             =item *
142              
143             The name of the social media site's icon as represented in Font Awesome
144             (probably a key from the `$urls` field).
145              
146             =back
147              
148             =cut
149              
150             method social_icon_template {
151             return q[];
152             }
153              
154             =head2 mk_social_icon
155              
156             Returns a fragment of HTML that will be used to display the social media
157             account on the web site.
158              
159             =cut
160              
161             method mk_social_icon {
162             return sprintf $self->social_icon_template,
163             $urls->{$service}{name}, $self->mk_social_link(), $service;
164             }
165             }
166              
167             =head1 AUTHOR
168              
169             Dave Cross
170              
171             =head1 COPYRIGHT AND LICENCE
172              
173             Copyright (c) 2024, Magnum Solutions Ltd. All Rights Reserved.
174              
175             This library is free software; you can redistribute it and/or modify it
176             under the same terms as Perl itself.
177              
178             =cut
179              
180             1;