App-LinkSite

 view release on metacpan or  search on metacpan

lib/App/LinkSite/Social.pm  view on Meta::CPAN


class App::LinkSite::Social {
  our $VERSION = '0.1.1';
  use strict;
  use warnings;
  use feature qw[say signatures];
  no if $] >= 5.038, 'warnings', qw[experimental::signatures experimental::class];

  field $service :reader :param;
  field $handle :reader :param;
  field $url :reader :param = undef;

  # TODO: This needs to be a class field.
  field $urls = {
    facebook   => {
      url  => "https://facebook.com/",
      name => 'Facebook',
    },
    'x-twitter' => {
      # This is currently still the correct URL
      url  => "https://twitter.com/",
      name => 'X/Twitter',
    },
    instagram  => {
      url  => "https://instagram.com/",
      name => 'Instagram',
    },
    tiktok     => {
      url  => "https://tiktok.com/@",
      name => 'TikTok',
    },
    linkedin   => {
      url  => "https://linkedin.com/in/",
      name => 'LinkedIn',
    },
    substack   => {
      url  => "https://XXXX.substack.com/",
      name => 'Substack',
    },
    github     => {
      url  => "https://github.com/",
      name => 'GitHub',
    },
    medium     => {
      url  => "https://XXXX.medium.com/",
      name => 'Medium',
    },
    reddit     => {
      url  => "https://reddit.com/user/",
      name => 'Reddit',
    },
    quora      => {
      url  => "https://quora.com/profile/",
      name => 'Quora',
    },
    mastodon   => {
      # Hmm...
      url  => "https://fosstodon.org/@",
      name => 'Mastodon',
    },
    threads    => {
      url  => "https://www.threads.net/@",
      name => 'Threads',
    },
    bluesky   => {
      url  => 'https://bsky.app/profile/',
      name => 'Bluesky',
    },
    letterboxd => {
      url  => 'https://letterboxd.com/',
      name => 'Letterboxd',
    },
    lastfm => {
      url  => 'https://last.fm/user/',
      name => 'last.fm',
    },
  };

=head1 METHODS

=head2 mk_social_link

Return a fragment of HTML that is used to represent this social media link
on the link site.

=cut

  method mk_social_link {
    return $url if $url;

    my $social_url;

    if (exists $urls->{$service}) {
      $social_url = $urls->{$service}{url};
    } else {
      warn('Unknown social service: ', $service);
      return;
    }

    if ($social_url =~ /XXXX/) {
      $social_url =~ s/XXXX/$handle/g;
    } else {
      $social_url .= $handle;
    }

    return $social_url;
  }


=head2 social_icon_template

Return a string that is used to produce the HTML that displays the social
icon and link on the link site. The template string will expect three
substitution values:

=over 4

=item *

The title for the link (probably the `name` from the `$urls` field)

=item *



( run in 2.228 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )