| 1 | package Yukki::Model::Root; | ||||||||||||||||||||||||||||||||
| 2 | 3 | $Yukki::Model::Root::VERSION = '0.991_002'; # TRIAL | |||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | $Yukki::Model::Root::VERSION = '0.991002';use v5.24; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 3 | extends 'Yukki::Model'; | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Type::Params qw( validate ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Type::Utils; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Types::Standard qw( Bool Maybe Str Dict slurpy ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Types::URI qw( Uri ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | # ABSTRACT: model for accessing the git repositories | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | sub repository { shift->app->model('Repository', { name => shift }) } | ||||||||||||||||||||||||||||||
|
Subroutine
repository: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | sub attach_repository { | ||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my ($self, %opt) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
attach_repository: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 25 | my $key = delete $opt{key} | ||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | // die "missing key in attach_repository"; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $opt{"key"} // die("missing key in attach_repository")
MC/DC0%0/1
delete $opt{"key"} // die("missing key in attach_repository")
delete $opt{"key"}
Truth table0%0/2
A
A= delete $opt{"key"}
| |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 0 | my $repo = Yukki::Settings::Repository->new(\%opt); | |||||||||||||||||||||||||||||||
| 29 | 0 | my $repo_file = $self->locate('repo_path', $key); | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($self->app->settings->repositories->{$key}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 32 | 0 | die "repository with key '$key' is already defined in the master configuraiton file, cannot attach it again"; | |||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | elsif (-e $self->locate('repo_path', $key)) { | ||||||||||||||||||||||||||||||||
| 35 | 0 | die "repository with key '$key' is already configured, cannot attach it again"; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 0 | $repo_file->spew_utf8($repo->dump_yaml); | |||||||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | sub init_repository { | ||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | my ($self, $opt) | ||||||||||||||||||||||||||||||
|
Subroutine
init_repository: called CC=6 SCAR=21.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 45 | = validate(\@_, class_type(__PACKAGE__), | ||||||||||||||||||||||||||||||||
| 46 | slurpy Dict[ | ||||||||||||||||||||||||||||||||
| 47 | key => Str, | ||||||||||||||||||||||||||||||||
| 48 | origin => Maybe[Uri], | ||||||||||||||||||||||||||||||||
| 49 | init_from_settings => Bool, | ||||||||||||||||||||||||||||||||
| 50 | ], | ||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||
| 52 | 3 | my ($key, $origin, $init_from_settings) = @{$opt}{qw( | |||||||||||||||||||||||||||||||
| 53 | key origin init_from_settings | ||||||||||||||||||||||||||||||||
| 54 | )}; | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 3 | my $repo_config = $self->app->settings->repositories->{$key}; | |||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | if ($repo_config && !$init_from_settings) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$repo_config and not $init_from_settings
MC/DC0%0/2
$repo_config and not $init_from_settings
$repo_config
not $init_from_settings
Truth table33%1/3
A and not(B)
A= $repo_configB= not $init_from_settings
| |||||||||||||||||||||||||||||||||
| 58 | 0 | die "unable to initialize repository '$key' found in settings, please use the command-line tools"; | |||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | elsif (!$repo_config) { | ||||||||||||||||||||||||||||||||
| 62 | 0 | my $repo_file = ''.$self->locate('repo_path', $key); | |||||||||||||||||||||||||||||||
| 63 | 0 | $repo_config = Yukki::Settings::Repository->load_yaml( | |||||||||||||||||||||||||||||||
| 64 | $repo_file->slurp_utf8 | ||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 3 | ▶ | die "repository '$key' not yet attached" if !$repo_config; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 3 | my $repository = $self->repository($key); | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | if ($origin) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 0 | $repository->clone_repository($origin); | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||||||||||||
| 76 | 3 | $repository->initialize_repository; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 3 | 1; | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | =pod | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | Yukki::Model::Root - model for accessing the git repositories | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | version 0.991_002 | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | my $root = $app->model('Root'); | ||||||||||||||||||||||||||||||||
| 99 | my $repository = $root->repository({ name => 'main' }); | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | This model contains method for performing actions related to the creation, deletion, and management of a set of git repositories as well as manipulating the configuration file. This model behaves as a singleton per L<Yukki> app. | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | This model will be used by various administrative features of scripts and the application. For the various methods that perform modifications to work, the tool performing the actions must have write access to the configuration and the directory containing the repositories. | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | =head1 EXTENDS | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | L<Yukki::Model> | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | =head2 repository | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | $repository = $root->repository($key); | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | This will construct and return a L<Yukki::Model::Repository> object. It's basically a synonym for: | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | $repository = $app->model('Repository', { name => $key }); | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | =head2 attach_repository | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | $root->attach_repository(%config); | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | Given the configuration for a repository, this will insert the configuration into the settings file. This will only insert a new configuration. It will not modify an existing one. For that you want L</edit_repository>. | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | This will create a new repository configuration file under L<Yukki::Settings/repo_path>. If a configuration with the same name already exists there or if one is defined within the C<YUKKI_CONFIG> file, this operation will fail. | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | The configuration to pass in is passed through to the constructor of L<Yukki::Settings::Repository>. You will also need to pass C<key> in, which is set to the key under which this repository will be saved. | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | =head2 init_repository | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | $repository = $root->init_repository( | ||||||||||||||||||||||||||||||||
| 134 | key => $key, | ||||||||||||||||||||||||||||||||
| 135 | origin => $git_uri, | ||||||||||||||||||||||||||||||||
| 136 | init_from_settings => $init_from_settings_flag, | ||||||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | This will initialize a new repository on disk. If C<origin> is given, the new repository will be cloned from there. If not, a new empty repository will be committed and then a single commit inserted containing an index stub. | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | Before calling this method, the L</attach_repository> method must be called first to configure it. | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | The C<init_from_settings> flag is set to a true value (default is false), then this will allow init of repositories found in L<Yukki::Settings>. This is intended for use by command-line tools only. Initializing C<YUKKI_CONFIG> defined repositories from the application is not advised. | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | This software is copyright (c) 2017 by Qubling Software LLC. | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 154 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | =cut | ||||||||||||||||||||||||||||||||