« CPAN/Maker/Bootstrapper/Role/UpdateAvailable.pm
↑ Summary
CPAN/Maker/Bootstrapper/Role/CreateConfig.pm »
| 1 | package CPAN::Maker::Bootstrapper::ConfigReader; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Config::Tiny; | ||
| 7 | use File::HomeDir; | ||
| 8 | |||
| 9 | use parent qw(Class::Accessor::Fast); | ||
| 10 | |||
| 11 | __PACKAGE__->follow_best_practice; | ||
| 12 | __PACKAGE__->mk_accessors(qw(config config_file)); | ||
| 13 | |||
| 14 | ######################################################################## | ||
| 15 | sub new { | ||
| 16 | ######################################################################## | ||
| 17 | my ( $class, $file ) = @_; | ||
| 18 | |||
| 19 | ($file) = grep {defined} ( $file, $ENV{CPAN_MAKER_CONFIG}, File::HomeDir->my_home . '/.gitconfig' ); | ||
| 20 | |||
| 21 | die "ERROR: no configuration file\n" | ||
| 22 | if !$file || !-e $file; | ||
| 23 | |||
| 24 | my $config = Config::Tiny->read($file) | ||
| 25 | or die "ERROR: Could not read $file: " . Config::Tiny->errstr . "\n"; | ||
| 26 | |||
| 27 | my $self = $class->SUPER::new( { config => $config, config_file => $file } ); | ||
| 28 | |||
| 29 | return $self; | ||
| 30 | } | ||
| 31 | |||
| 32 | ######################################################################## | ||
| 33 | sub get_value { | ||
| 34 | ######################################################################## | ||
| 35 | my ( $self, $section, $parameter ) = @_; | ||
| 36 | |||
| 37 | return $self->get_config->{$section}->{$parameter}; | ||
| 38 | } | ||
| 39 | |||
| 40 | ######################################################################## | ||
| 41 | sub user_name { | ||
| 42 | ######################################################################## | ||
| 43 | my ($self) = @_; | ||
| 44 | return $self->get_value( 'user', 'name' ); | ||
| 45 | } | ||
| 46 | |||
| 47 | ######################################################################## | ||
| 48 | sub user_github { | ||
| 49 | ######################################################################## | ||
| 50 | my ($self) = @_; | ||
| 51 | return $self->get_value( 'user', 'github' ); | ||
| 52 | } | ||
| 53 | |||
| 54 | ######################################################################## | ||
| 55 | sub user_email { | ||
| 56 | ######################################################################## | ||
| 57 | my ($self) = @_; | ||
| 58 | return $self->get_value( 'user', 'email' ); | ||
| 59 | } | ||
| 60 | |||
| 61 | ######################################################################## | ||
| 62 | sub cpan_maker_basedir { | ||
| 63 | ######################################################################## | ||
| 64 | my ($self) = @_; | ||
| 65 | |||
| 66 | return $self->get_value( 'cpan-maker', 'basedir' ); | ||
| 67 | } | ||
| 68 | |||
| 69 | ######################################################################## | ||
| 70 | sub cpan_maker_max_tokens { | ||
| 71 | ######################################################################## | ||
| 72 | my ($self) = @_; | ||
| 73 | |||
| 74 | return $self->get_value( 'cpan-maker', 'max-tokens' ); | ||
| 75 | } | ||
| 76 | |||
| 77 | ######################################################################## | ||
| 78 | sub cpan_maker_resources { | ||
| 79 | ######################################################################## | ||
| 80 | my ($self) = @_; | ||
| 81 | |||
| 82 | return $self->get_value( 'cpan-maker', 'resources' ); | ||
| 83 | } | ||
| 84 | |||
| 85 | ######################################################################## | ||
| 86 | sub cpan_maker_perltidyrc { | ||
| 87 | ######################################################################## | ||
| 88 | my ($self) = @_; | ||
| 89 | |||
| 90 | return $self->get_value( 'cpan-maker', 'perltidyrc' ); | ||
| 91 | } | ||
| 92 | |||
| 93 | ######################################################################## | ||
| 94 | sub cpan_maker_perlcriticrc { | ||
| 95 | ######################################################################## | ||
| 96 | my ($self) = @_; | ||
| 97 | |||
| 98 | return $self->get_value( 'cpan-maker', 'perlcriticrc' ); | ||
| 99 | } | ||
| 100 | |||
| 101 | ######################################################################## | ||
| 102 | sub cpan_maker_syntax_checking { | ||
| 103 | ######################################################################## | ||
| 104 | my ($self) = @_; | ||
| 105 | |||
| 106 | return $self->get_value( 'cpan-maker', 'syntax-checking' ); | ||
| 107 | } | ||
| 108 | |||
| 109 | ######################################################################## | ||
| 110 | sub cpan_maker_llm_api_key_helper { | ||
| 111 | ######################################################################## | ||
| 112 | my ($self) = @_; | ||
| 113 | |||
| 114 | return $self->get_value( 'cpan-maker', 'llm-api-key-helper' ); | ||
| 115 | } | ||
| 116 | |||
| 117 | 1; | ||
| 118 | |||
| 119 | __END__ |