There is an ongoing outage on the primary CPAN mirror. It is possible to work around the issue by using MetaCPAN as a mirror.

NAME

MooX::Role::SEOTags - A role for generating SEO meta tags (OpenGraph, Twitter, etc)

SYNOPSIS

package MyWebPage;
use Moo;
with 'MooX::Role::SEOTags';

has og_title       => (is => 'ro', required => 1);
has og_type        => (is => 'ro', required => 1);
has og_description => (is => 'ro', required => 1);
has og_url         => (is => 'ro', required => 1);
has og_image       => (is => 'ro'); # optional

# And later, in the code that builds the website

my $page = MyWebPage->new(
  og_title       => "My Page Title",
  og_type        => "website",
  og_description => 'This is a lovely website',
  og_url         => "https://example.com/my-page",
  og_image       => "https://example.com/image.jpg",
);

# Print tags separately

print $page->title_tag;
print $page->canonical_tag;
print $page->og_tags;

# Or print all tags at once

print $page->tags;

DESCRIPTION

This role provides methods to generate SEO meta tags for web pages, including OpenGraph and Twitter tags. It requires the consuming class to implement the following attributes or methods:

  • og_title - The title of the page

  • og_type - The type of the page (e.g., "website", "article")

  • og_description - The description of the page

  • og_url - The canonical URL of the page

  • og_image - The URL of an image representing the content (optional)

The role provides methods to generate individual tags as well as a method to generate all tags at once.

METHODS

title_tag

Returns the HTML title tag.

canonical_tag

Returns the HTML canonical link tag.

description_tag

Returns the HTML meta description tag.

og_title_tag

Returns the OpenGraph title meta tag.

og_type_tag

Returns the OpenGraph type meta tag.

og_description_tag

Returns the OpenGraph description meta tag.

og_url_tag

Returns the OpenGraph URL meta tag.

og_image_tag

Returns the OpenGraph image meta tag if the og_image attribute is provided.

og_tags

Returns all OpenGraph meta tags as a single string.

twitter_card_tag

Returns the Twitter card meta tag.

twitter_title_tag

Returns the Twitter title meta tag.

twitter_description_tag

Returns the Twitter description meta tag.

twitter_image_tag

Returns the Twitter image meta tag if the og_image attribute is provided.

twitter_tags

Returns all Twitter meta tags as a single string.

tags

Returns all tags (title, canonical, and OpenGraph) as a single string.

AUTHOR

Dave Cross <dave@perlhacks.com>

COPYRIGHT

Copyright (c) 2025 Magnum Solutions Ltd. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.