Dist::Zilla::Util - random snippets of code that Dist::Zilla wants


Dist-Zilla documentation Contained in the Dist-Zilla distribution.

Index


Code Index:

NAME

Top

Dist::Zilla::Util - random snippets of code that Dist::Zilla wants

VERSION

Top

version 4.200008

METHODS

Top

abstract_from_file

This method, which is likely to change or go away, tries to guess the abstract of a given file, assuming that it's Perl code. It looks for a POD =head1 section called "NAME" or a comment beginning with ABSTRACT:.

expand_config_package_name

  my $pkg_name = Util->expand_config_package_name($string);

This method, which is likely to change or go away, rewrites the given string into a package name. Consult Dist::Zilla::Config (Dist::Zilla::Config) for more information.

AUTHOR

Top

Ricardo SIGNES <rjbs@cpan.org>

COPYRIGHT AND LICENSE

Top


Dist-Zilla documentation Contained in the Dist-Zilla distribution.

use strict;
use warnings;
package Dist::Zilla::Util;
BEGIN {
  $Dist::Zilla::Util::VERSION = '4.200008';
}
# ABSTRACT: random snippets of code that Dist::Zilla wants

use File::HomeDir ();
use Path::Class;
use String::RewritePrefix 0.002; # better string context behavior

{
  package
    Dist::Zilla::Util::PEA;
  use Pod::Eventual 0.091480; # better nonpod/blank events
  use base 'Pod::Eventual';
  sub _new  { bless {} => shift; }
  sub handle_nonpod {
    my ($self, $event) = @_;
    return if $self->{abstract};
    return $self->{abstract} = $1
      if $event->{content}=~ /^\s*#+\s*ABSTRACT:\s*(.+)$/m;
    return;
  }
  sub handle_event {
    my ($self, $event) = @_;
    return if $self->{abstract};
    if (
      ! $self->{in_name}
      and $event->{type} eq 'command'
      and $event->{command} eq 'head1'
      and $event->{content} =~ /^NAME\b/
    ) {
      $self->{in_name} = 1;
      return;
    }

    return unless $self->{in_name};

    if (
      $event->{type} eq 'text'
      and $event->{content} =~ /^\S+\s+-+\s+(.+)$/
    ) {
      $self->{abstract} = $1;
    }
  }
}


sub abstract_from_file {
  my ($self, $file) = @_;
  my $e = Dist::Zilla::Util::PEA->_new;
  $e->read_string($file->content);
  return $e->{abstract};
}


sub expand_config_package_name {
  my ($self, $package) = @_;

  my $str = String::RewritePrefix->rewrite(
    {
      '=' => '',
      '@' => 'Dist::Zilla::PluginBundle::',
      '%' => 'Dist::Zilla::Stash::',
      ''  => 'Dist::Zilla::Plugin::',
    },
    $package,
  );

  return $str;
}

sub _global_config_root {
  return dir($ENV{DZIL_GLOBAL_CONFIG_ROOT}) if $ENV{DZIL_GLOBAL_CONFIG_ROOT};

  my $homedir = File::HomeDir->my_home
    or Carp::croak("couldn't determine home directory");

  return dir($homedir)->subdir('.dzil');
}

1;

__END__