| 1 | package CPAN::Maker::Bootstrapper::Role::ShowDefaults; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use CLI::Simple::Constants qw(:booleans); | ||
| 7 | use CLI::Simple::Utils qw(choose); | ||
| 8 | use Cwd qw(abs_path); | ||
| 9 | |||
| 10 | use Data::Dumper; | ||
| 11 | use English qw(-no_match_vars); | ||
| 12 | use File::HomeDir; | ||
| 13 | use Role::Tiny; | ||
| 14 | |||
| 15 | ######################################################################## | ||
| 16 | sub cmd_show_defaults { | ||
| 17 | ######################################################################## | ||
| 18 | my ($self) = @_; | ||
| 19 | |||
| 20 | my $defaults = $self->_resolve_defaults; | ||
| 21 | |||
| 22 | foreach my $default ( sort { $a->[0] cmp $b->[0] } @{$defaults} ) { | ||
| 23 | my ( $name, $value ) = @{$default}; | ||
| 24 | |||
| 25 | if ( !defined $value || $value eq q{} ) { | ||
| 26 | $value = '<not set>'; | ||
| 27 | } | ||
| 28 | |||
| 29 | printf "%-20s %s\n", $name, $value; | ||
| 30 | } | ||
| 31 | |||
| 32 | return $SUCCESS; | ||
| 33 | } | ||
| 34 | |||
| 35 | ######################################################################## | ||
| 36 | sub _resolve_defaults { | ||
| 37 | ######################################################################## | ||
| 38 | my ($self) = @_; | ||
| 39 | |||
| 40 | my $installdir = $self->get_installdir; | ||
| 41 | |||
| 42 | if ( !$installdir ) { | ||
| 43 | $installdir = sprintf '%s/{module-name}', $self->get_basedir; | ||
| 44 | } | ||
| 45 | |||
| 46 | my $reader = $self->get_reader; | ||
| 47 | |||
| 48 | my @config = ( | ||
| 49 | [ config_source => $self->get_config ], | ||
| 50 | [ basedir => $self->get_basedir ], | ||
| 51 | [ installdir => $installdir ], | ||
| 52 | [ username => $self->get_username ], | ||
| 53 | [ email => $self->get_email ], | ||
| 54 | [ github_user => $self->get_github_user ], | ||
| 55 | [ resources => $self->get_resources ], | ||
| 56 | [ color => $self->get_color ? 'on' : 'off' ], | ||
| 57 | [ llm_api_key_helper => $self->get_llm_api_key_helper ], | ||
| 58 | [ max_tokens => $self->get_max_tokens ], | ||
| 59 | [ max_diff_files => $self->get_max_diff_files ], | ||
| 60 | ); | ||
| 61 | |||
| 62 | my $syntax_checking = choose { | ||
| 63 | return $ENV{SYNTAX_CHECKING} | ||
| 64 | if exists $ENV{SYNTAX_CHECKING}; | ||
| 65 | |||
| 66 | return $reader->cpan_maker_syntax_checking | ||
| 67 | if $reader && defined $reader->cpan_maker_syntax_checking; | ||
| 68 | |||
| 69 | return; | ||
| 70 | }; | ||
| 71 | |||
| 72 | push @config, [ syntax_checking => $syntax_checking ]; | ||
| 73 | |||
| 74 | my $home = File::HomeDir->my_home; | ||
| 75 | |||
| 76 | my $perltidyrc = choose { | ||
| 77 | return abs_path( $ENV{PERLTIDYRC} ) | ||
| 78 | if $ENV{PERLTIDYRC} && -e abs_path( $ENV{PERLTIDYRC} ); | ||
| 79 | |||
| 80 | return $reader->cpan_maker_perltidyrc | ||
| 81 | if $reader && defined $reader->cpan_maker_perltidyrc; | ||
| 82 | |||
| 83 | return abs_path('.perltidyrc') | ||
| 84 | if -e '.perltidyrc'; | ||
| 85 | |||
| 86 | return abs_path('perltidyrc') | ||
| 87 | if -e 'perltidyrc'; | ||
| 88 | |||
| 89 | return "$home/.perltidyrc" | ||
| 90 | if -e "$home/.perltidyrc"; | ||
| 91 | |||
| 92 | return; | ||
| 93 | }; | ||
| 94 | |||
| 95 | push @config, [ perltidyrc => $perltidyrc ]; | ||
| 96 | |||
| 97 | my $perlcriticrc = choose { | ||
| 98 | return abs_path( $ENV{PERLCRITICRC} ) | ||
| 99 | if $ENV{PERLCRITICRC} && -e abs_path( $ENV{PERLCRITICRC} ); | ||
| 100 | |||
| 101 | return $reader->cpan_maker_perlcriticrc | ||
| 102 | if $reader && defined $reader->cpan_maker_perlcriticrc; | ||
| 103 | |||
| 104 | return abs_path('.perlcriticrc') | ||
| 105 | if -e '.perlcriticrc'; | ||
| 106 | |||
| 107 | return abs_path('perlcriticrc') | ||
| 108 | if -e 'perlcriticrc'; | ||
| 109 | |||
| 110 | return "$home/.perlcriticrc" | ||
| 111 | if -e "$home/.perlcriticrc"; | ||
| 112 | |||
| 113 | return; | ||
| 114 | }; | ||
| 115 | |||
| 116 | push @config, [ perlcriticrc => $perlcriticrc ]; | ||
| 117 | |||
| 118 | return \@config; | ||
| 119 | } | ||
| 120 | |||
| 121 | 1; |