package System::Introspector::Report::Publish::API;
use Moo::Role;

requires qw(
  publish
);

sub _prepare_matcher_from {
  my ($self, $matchers) = @_;
  my $pattern = join '|', map {
    my @elements = split m{:}, $_;
    join qr{\0}, map {
      ($_ eq '*') ? qr{[^\0]+} : qr{\Q$_\E};
    } split m{:}, $_;
  } ref($matchers) ? @$matchers : $matchers;
  return qr{^(?:$pattern)$};
}

sub _match_id {
  my ($self, $report, $match) = @_;
  $match = $self->_prepare_matcher_from($match)
    unless ref($match) eq 'Regexp';
  my $id = join "\0", ref($report->{id})
    ? @{$report->{id}}
    : ($report->{id});
  return $id =~ $match;
}

1;
