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::OpenGraph - A role for generating OpenGraph meta tags

SYNOPSIS

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

has 'og_title' => (is => 'ro', required => 1);
has 'og_type'  => (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 websote',
  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 OpenGraph meta tags for web pages. 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_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.

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.

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.