Skip to content

Create and use a new "HasURL" role #147

Description

@davorg

The recent canonical URL fix highlighted that URL generation logic is spread across the application. Consider moving URL construction into model objects via a HasURL role.

Something like this:

role Succession::Role::HasURL {
  requires qw[identifier];

  method prefix { return undef }

  method url {
    return join '/',
      '',
      grep { defined && length }
      $self->prefix,
      $self->identifier;
  }
}

And then, in the Person class:

method prefix     { 'p' }
method identifier { $self->slug }

Might need a Date class too:

method identifier { $self->canonical_date }

And, perhaps, we can also use it for the reference pages.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions