<commit_before>module PackageManager
  class CPAN < Base
    HAS_VERSIONS = true
    HAS_DEPENDENCIES = true
    BIBLIOTHECARY_SUPPORT = true
    URL = 'https://metacpan.org'
    COLOR = '#0298c3'

    def self.package_link(project, version = nil)
      "https://metacpan.org/release/#{project.name}"
    end

    def self.project_names
      page = 1
      projects = []
      while true
        r = get("http://api.metacpan.org/v0/release/_search?q=status:latest&fields=distribution&sort=date:desc&size=5000&from=#{page*5000}")['hits']['hits']
        break if r == []
        projects += r
        page +=1
      end
      projects.map{|project| project['fields']['distribution'] }.uniq
    end

    def self.recent_names
      names = get('http://api.metacpan.org/v0/release/_search?q=status:latest&fields=distribution&sort=date:desc&size=100')['hits']['hits']
      names.map{|project| project['fields']['distribution'] }.uniq
    end

    def self.project(name)
      get("http://api.metacpan.org/v0/release/#{name}")
    end

    def self.mapping(project)
      {
        :name => project['distribution'],
        :homepage => project.fetch('resources',{})['homepage'],
        :description => project['abstract'],
        :licenses => project['license'].join(','),
        :repository_url => repo_fallback(project.fetch('resources',{}).fetch('repository',{})['web'], project.fetch('resources',{})['homepage']),
        :versions => get("http://api.metacpan.org/v0/release/_search?q=distribution:#{project['distribution']}&size=5000&fields=version,dependency")['hits']['hits']
      }
    end

    def self.versions(project)
      versions = get("http://api.metacpan.org/v0/release/_search?q=distribution:#{project['distribution']}&size=5000&fields=version,date")['hits']['hits']<commit_msg>Use new cpan api #1470<commit_after>module PackageManager
  class CPAN < Base
    HAS_VERSIONS = true
    HAS_DEPENDENCIES = true
    BIBLIOTHECARY_SUPPORT = true
    URL = 'https://metacpan.org'
    COLOR = '#0298c3'

    def self.package_link(project, version = nil)
      "https://metacpan.org/release/#{project.name}"
    end

    def self.project_names
      page = 1
      projects = []
      while true
        r = get("https://fastapi.metacpan.org/v1/release/_search?q=status:latest&fields=distribution&sort=date:desc&size=5000&from=#{page*5000}")['hits']['hits']
        break if r == []
        projects += r
        page +=1
      end
      projects.map{|project| project['fields']['distribution'] }.uniq
    end

    def self.recent_names
      names = get('https://fastapi.metacpan.org/v1/release/_search?q=status:latest&fields=distribution&sort=date:desc&size=100')['hits']['hits']
      names.map{|project| project['fields']['distribution'] }.uniq
    end

    def self.project(name)
      get("https://fastapi.metacpan.org/v1/release/#{name}")
    end

    def self.mapping(project)
      {
        :name => project['distribution'],
        :homepage => project.fetch('resources',{})['homepage'],
        :description => project['abstract'],
        :licenses => project['license'].join(','),
        :repository_url => repo_fallback(project.fetch('resources',{}).fetch('repository',{})['web'], project.fetch('resources',{})['homepage']),
        :versions => get("https://fastapi.metacpan.org/v1/release/_search?q=distribution:#{project['distribution']}&size=5000&fields=version,dependency")['hits']['hits']
      }
    end

    def self.versions(project)
      versions = get("https://fastapi.metacpan.org/v1/release/_search?q=distribution:#{project['distribution']}&size=5000&fields=version,date")['hits']['hits']
{'fraction_non_alphanumeric': 0.18209366391184573, 'fraction_numerical': 0.01818181818181818, 'mean_word_length': 3.74640522875817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4649332', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1132, 'n_words': 151}