
    Vh+                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
Z
d dlmZmZ d dlmZ  G d d	e      Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: cpanm
short_description: Manages Perl library dependencies
description:
  - Manage Perl library dependencies using cpanminus.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  name:
    type: str
    description:
      - The Perl library to install. Valid values change according to the O(mode), see notes for more details.
      - Note that for installing from a local path the parameter O(from_path) should be used.
    aliases: [pkg]
  from_path:
    type: path
    description:
      - The local directory or C(tar.gz) file to install from.
  notest:
    description:
      - Do not run unit tests.
    type: bool
    default: false
  locallib:
    description:
      - Specify the install base to install modules.
    type: path
  mirror:
    description:
      - Specifies the base URL for the CPAN mirror to use.
    type: str
  mirror_only:
    description:
      - Use the mirror's index file instead of the CPAN Meta DB.
    type: bool
    default: false
  installdeps:
    description:
      - Only install dependencies.
    type: bool
    default: false
  install_recommendations:
    description:
      - If V(true), installs dependencies declared as recommends per META spec.
      - If V(false), it ensures the dependencies declared as recommends are not installed, overriding any decision made earlier in E(PERL_CPANM_OPT).
      - If parameter is not set, C(cpanm) will use its existing defaults.
      - When these dependencies fail to install, cpanm continues the installation, since they are just recommendation.
    type: bool
    version_added: 10.3.0
  install_suggestions:
    description:
      - If V(true), installs dependencies declared as suggests per META spec.
      - If V(false), it ensures the dependencies declared as suggests are not installed, overriding any decision made earlier in E(PERL_CPANM_OPT).
      - If parameter is not set, C(cpanm) will use its existing defaults.
      - When these dependencies fail to install, cpanm continues the installation, since they are just suggestion.
    type: bool
    version_added: 10.3.0
  version:
    description:
      - Version specification for the perl module. When O(mode) is V(new), C(cpanm) version operators are accepted.
    type: str
  executable:
    description:
      - Override the path to the cpanm executable.
    type: path
  mode:
    description:
      - Controls the module behavior. See notes below for more details.
      - The default changed from V(compatibility) to V(new) in community.general 9.0.0.
    type: str
    choices: [compatibility, new]
    default: new
    version_added: 3.0.0
  name_check:
    description:
      - When O(mode=new), this parameter can be used to check if there is a module O(name) installed (at O(version), when
        specified).
    type: str
    version_added: 3.0.0
notes:
  - Please note that U(http://search.cpan.org/dist/App-cpanminus/bin/cpanm, cpanm) must be installed on the remote host.
  - 'This module now comes with a choice of execution O(mode): V(compatibility) or V(new).'
  - 'O(mode=compatibility): When using V(compatibility) mode, the module will keep backward compatibility. This was the default
    mode before community.general 9.0.0. O(name) must be either a module name or a distribution file. If the perl module given
    by O(name) is installed (at the exact O(version) when specified), then nothing happens. Otherwise, it will be installed
    using the C(cpanm) executable. O(name) cannot be an URL, or a git URL. C(cpanm) version specifiers do not work in this
    mode.'
  - 'O(mode=new): When using V(new) mode, the module will behave differently. The O(name) parameter may refer to a module
    name, a distribution file, a HTTP URL or a git repository URL as described in C(cpanminus) documentation. C(cpanm) version
    specifiers are recognized. This is the default mode from community.general 9.0.0 onwards.'
seealso:
  - name: C(cpanm) command manual page
    description: Manual page for the command.
    link: https://metacpan.org/dist/App-cpanminus/view/bin/cpanm
author:
  - "Franck Cuny (@fcuny)"
  - "Alexei Znamensky (@russoz)"
aI  
- name: Install Dancer perl package
  community.general.cpanm:
    name: Dancer

- name: Install version 0.99_05 of the Plack perl package
  community.general.cpanm:
    name: MIYAGAWA/Plack-0.99_05.tar.gz

- name: Install Dancer into the specified locallib
  community.general.cpanm:
    name: Dancer
    locallib: /srv/webapps/my_app/extlib

- name: Install perl dependencies from local directory
  community.general.cpanm:
    from_path: /srv/webapps/my_app/src/

- name: Install Dancer perl package without running the unit tests in indicated locallib
  community.general.cpanm:
    name: Dancer
    notest: true
    locallib: /srv/webapps/my_app/extlib

- name: Install Dancer perl package from a specific mirror
  community.general.cpanm:
    name: Dancer
    mirror: 'http://cpan.cpantesters.org/'

- name: Install Dancer perl package into the system root path
  become: true
  community.general.cpanm:
    name: Dancer

- name: Install Dancer if it is not already installed OR the installed version is older than version 1.0
  community.general.cpanm:
    name: Dancer
    version: '1.0'
z
cpanm_version:
  description: Version of CPANMinus.
  type: str
  returned: always
  sample: "1.7047"
  version_added: 10.0.0
N)	CmdRunnercmd_runner_fmt)ModuleHelperc                      e Zd ZddgZ e e eddg       ed       ed       edd	
       ed       ed       edd	
       edd	
       ed       ed       ed       eddddg       ed            dg      ZdZ e ej                  d       ej                  d       ej                  d       ej                  d       ej                  d       ej                  ddd       ej                  ddd       ej                          ej                  d      	      Zd	Zd Zd  Zd! Zd" Zy#)$	CPANMinusnameversionstrpkg)typealiases)r   pathboolF)r   defaultnewcompatibility)r   r   choices)r   r   	from_pathnotestlocallibmirrormirror_onlyinstalldepsinstall_recommendationsinstall_suggestions
executablemode
name_check)r   r   )argument_specrequired_one_ofcpanmz--notestz--local-libz--mirrorz--mirror-onlyz--installdepsz--with-recommendsz--without-recommendsT)ignore_nonez--with-suggestsz--without-suggestsz	--version)	r   r   r   r   r   r   r   pkg_speccpanm_versionc                    | j                   }|j                  dk(  r|j                  r;| j                  d       n)|j                  r|j
                  r| j                  d       |j                  r|j                  n| j                  | _        t        | j                  | j                  | j                  d      | _        | j                  j                  | j                   _        | j                  d      5 }|j                         \  }}}|j                  d      d   }t        j                   d	|      }|s | j                  d
j#                  |             |j%                  d      | j                   _        d d d        y # 1 sw Y   y xY w)Nr   z3Parameter name_check can only be used with mode=newzHParameters 'name' and 'from_path' are mutually exclusive when 'mode=new'T)check_rcr'   
r   zversion\s+([\d\.]+)\s+z=Failed to determine version number. First line of output: {0}   )varsr    r!   do_raiser   r   r   commandr   modulecommand_args_formatsrunnerbinaryrunsplitresearchformatgroupr'   )selfvctxrcouterrlinematchs           k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/cpanm.py__init_module__zCPANMinus.__init_module__   s   II66_$||STvv!++hi'(||q||T\\4;T;T_cd;;--		[[) 	5S779LBS99T?1%DII7>E]ddeijk&+kk!nDII#	5 	5 	5s   4BE>>Fc                 (   d }||j                  d      ry|dnd|z   }|rdd|z  ini }t        | j                  dd	gd
t        j                         id|      } |d
|      5 }|j                  d||d      cd d d        S # 1 sw Y   y xY w)Nc                     | dk(  S )Nr    )r<   r=   r>   s      rA   processz0CPANMinus._is_package_installed.<locals>.process   s    7N    .tar.gzF  PERL5LIBz%s/lib/perl5perlz-lemod)r)   environ_updateoutput_processzuse ;)rM   )endswithr   r/   r   as_listr3   )r9   r   r   r   rF   envr1   r;   s           rA   _is_package_installedzCPANMinus._is_package_installed   s    	 <4==3"S7]9Az>H45r4;;%AWAWAY9Zej{~E'2 	>c77dG<7=	> 	> 	>s   &BBc                 v   ||S |j                  d      r| j                  d       t        j                  j	                  |      r| j                  d       |j                  d      r@|j                  d      r| j                  d       |j                  d      r|nd|z   }||z   S |d	   d
vrd|z   }||z   S )NrH   z@parameter 'version' must not be used when installing from a file)msgzEparameter 'version' must not be used when installing from a directoryz.git~zQoperator '~' not allowed in version parameter when installing from git repository@r   )rY   rX   )rR   r-   osr   isdir
startswith)r9   r&   r   s      rA   sanitize_pkg_spec_versionz#CPANMinus.sanitize_pkg_spec_version   s    ?OY'MM`Ma77=="MMeMfV$!!#&"uv!(!3!3C!8gcGmG '!! QZz)GmG'!!rG   c                      fd} j                   }|j                  rdnd}|j                  dk(  r8 j                  |j                  |j
                  |j                        ry ||   }na|j                  r1 j                  |j                  |j
                  |j                        nd}|ry  j                  ||   |j                        } j                  g d|      5 }|j                  |       _        d d d        y # 1 sw Y   y xY w)	Nc                     j                   j                  dk(  r,| dk7  r'j                  |j                   j                         d|vxr d|vS )Nr   r   )rW   cmdzis up to date)r,   r    r-   cmd_args)r<   r=   r>   r9   s      rA   rF   z"CPANMinus.__run__.<locals>.process  sH    yy~~0R1W#499+=+=>"#-L/2LLrG   r   r   r   F)r   r   r   r   r   r   r   r&   rO   )r&   )r,   r   r    rU   r   r   r   r!   r]   r1   r3   changed)r9   rF   r:   	pkg_paramr&   	installedr;   s   `      rA   __run__zCPANMinus.__run__  s    	M
 II#$;;KF	66_$))!&&!**aiiH|H[\[g[g221<<QYYWmrI55a	lAIINH[[ 	
 "  	# 
	6 '*77H75DL
	6 
	6 
	6s    DD
N)__name__
__module____qualname__output_paramsdictr/   r.   r   as_bool
as_opt_valrS   as_fixedr0   use_old_vardictrB   rU   r]   re   rE   rG   rA   r
   r
      sj   Y'M55'2e$'VU3v&U#&%8&%8$(f$5 $& 1(5%/59QR'
 //!F& G%~%%j1***=9(~((4*N**?;*N**?; 6 6 67JLbpt u2N223DFZhlm''')-n--k:
 O5*>"6rG   r
   c                  ,    t         j                          y )N)r
   executerE   rG   rA   mainrq   "  s    rG   __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNrZ   r5   Eansible_collections.community.general.plugins.module_utils.cmd_runnerr   r   Hansible_collections.community.general.plugins.module_utils.module_helperr   r
   rq   rf   rE   rG   rA   <module>rz      sa    A @fP&P
 
 	 k aq6 q6h zF rG   