| 1 | package Geoffrey::Write; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use 5.016; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 3 | $Geoffrey::Write::VERSION = '0.000206'; | |||||||||||
| 9 | |||||||||||||
| 10 | 3 | ▶ | use parent 'Geoffrey::Role::Core'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 3 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 13 | 3 | my $class = shift; | |||||||||||
| 14 | 3 | my $self = $class->SUPER::new(@_); | |||||||||||
| 15 | $self->{changelog_types} = [ | ||||||||||||
| 16 | 3 | qw/sequences tables primaries uniques | |||||||||||
| 17 | foreigns indexes views functions triggers/ | ||||||||||||
| 18 | ]; | ||||||||||||
| 19 | 3 | return bless $self, $class; | |||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | 21 | ▶ | sub author { return $_[0]->{author} // 'Mario Zieschang'; } | ||||||||||
|
Subroutine
author: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$_[0]{"author"} // "Mario Zieschang"
MC/DC100%1/1
$_[0]{"author"} // "Mario Zieschang"
$_[0]{"author"}
Truth table100%2/2
A
A= $_[0]{"author"}
| |||||||||||||
| 23 | 20 | ▶ | sub changeset_key { return $_[0]->{changeset_key} // 'maz'; } | ||||||||||
|
Subroutine
changeset_key: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
$_[0]{"changeset_key"} // "maz"
MC/DC0%0/1
$_[0]{"changeset_key"} // "maz"
$_[0]{"changeset_key"}
Truth table50%1/2
A
A= $_[0]{"changeset_key"}
| |||||||||||||
| 24 | 13 | ▶ | sub inc_changelog_count { return $_[0]->{changelog_count}++; } | ||||||||||
|
Subroutine
inc_changelog_count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 25 | 34 | ▶ | sub changelog_count { $_[0]->{changelog_count} //= 0; return $_[0]->{changelog_count}; } | ||||||||||
|
Subroutine
changelog_count: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$_[0]{"changelog_count"} //= 0
MC/DC100%1/1
$_[0]{"changelog_count"} //= 0
$_[0]{"changelog_count"}
Truth table100%2/2
A
A= $_[0]{"changelog_count"}
| |||||||||||||
| 26 | |||||||||||||
| 27 | 20 | ▶ | sub changeset_id { | ||||||||||
|
Subroutine
changeset_id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 28 | 20 | my ($self, $i_count) = @_; | |||||||||||
| 29 | 20 | ▶ | return join q/-/, $self->changelog_count, $i_count ? $i_count : 1, $self->changeset_key; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 1 | ▶ | sub changeset { | ||||||||||
|
Subroutine
changeset: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 33 | 1 | my $self = shift; | |||||||||||
| 34 | 1 | ▶ | return $self->{changeset} if ($self->{changeset}); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 1 | require Geoffrey::Changeset; | |||||||||||
| 36 | 1 | $self->{changeset} = Geoffrey::Changeset->new(converter => $self->converter, dbh => $self->dbh,); | |||||||||||
| 37 | 1 | return $self->{changeset}; | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 1 | ▶ | sub run { | ||||||||||
|
Subroutine
run: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||
| 41 | 1 | my ($self, $s_dir, $s_schema, $b_dump) = @_; | |||||||||||
| 42 | 1 | my $o_changelog_io = $self->changelog_io; | |||||||||||
| 43 | # if changelog_io needs a dbh it must store the changelogs into a database | ||||||||||||
| 44 | # and not in a filepath | ||||||||||||
| 45 | 1 | ▶ | if ($o_changelog_io->needs_dbh) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 0 | $s_dir = q~changelog-~; | |||||||||||
| 47 | } | ||||||||||||
| 48 | else { | ||||||||||||
| 49 | 1 | require File::Path; | |||||||||||
| 50 | 1 | File::Path::make_path($s_dir); | |||||||||||
| 51 | 1 | $s_dir = $s_dir . q~/changelog-~; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 1 | my @a_changelogs = (); | |||||||||||
| 55 | 1 | for (@{$self->{changelog_types}}) { | |||||||||||
| 56 | 9 | ▶ | my $ar_data = eval { return $self->$_($s_schema, 1); } or do { next; }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 3 | ▶ | next if scalar @{$ar_data} == 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 3 | my $s_file = $s_dir . $self->inc_changelog_count . q/-/ . $_; | |||||||||||
| 59 | 3 | $o_changelog_io->write($s_file, $ar_data, $b_dump); | |||||||||||
| 60 | 3 | push @a_changelogs, $self->changelog_count . q/-/ . $_; | |||||||||||
| 61 | } | ||||||||||||
| 62 | 1 | return $o_changelog_io->write($s_dir . q~/changelog~, {changelogs => \@a_changelogs}, $b_dump); | |||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | 2 | ▶ | sub sequences { | ||||||||||
|
Subroutine
sequences: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 66 | 2 | my ($self, $s_schema) = @_; | |||||||||||
| 67 | 2 | require Geoffrey::Action::Constraint::Default; | |||||||||||
| 68 | return [{ | ||||||||||||
| 69 | 2 | id => $self->changeset_id, | |||||||||||
| 70 | author => $self->author, | ||||||||||||
| 71 | entries => | ||||||||||||
| 72 | Geoffrey::Action::Constraint::Default->new(dbh => $self->dbh, converter => $self->converter) | ||||||||||||
| 73 | ->list_from_schema($s_schema)}]; | ||||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 2 | ▶ | sub tables { | ||||||||||
|
Subroutine
tables: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 77 | 2 | my ($self, $s_schema, $include_columns) = @_; | |||||||||||
| 78 | 2 | my $count = 1; | |||||||||||
| 79 | 2 | require Geoffrey::Action::Table; | |||||||||||
| 80 | 2 | my $o_tables = Geoffrey::Action::Table->new(dbh => $self->dbh, converter => $self->converter); | |||||||||||
| 81 | |||||||||||||
| 82 | 9 | return [map { $self->map_entry([{action => 'table.add', name => $_}], $count++) } | |||||||||||
| 83 | 2 | ▶ | @{$o_tables->list_from_schema($s_schema)}] | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | if !$include_columns; | ||||||||||||
| 85 | |||||||||||||
| 86 | 1 | require Geoffrey::Action::Column; | |||||||||||
| 87 | 1 | my $o_columns = Geoffrey::Action::Column->new(dbh => $self->dbh, converter => $self->converter); | |||||||||||
| 88 | return [ | ||||||||||||
| 89 | map { | ||||||||||||
| 90 | 1 | $self->map_entry([{ | |||||||||||
| 91 | action => 'table.add', | ||||||||||||
| 92 | name => $_, | ||||||||||||
| 93 | columns => $o_columns->list_from_schema($s_schema, $_)} | ||||||||||||
| 94 | ], | ||||||||||||
| 95 | $count++ | ||||||||||||
| 96 | ) | ||||||||||||
| 97 | 1 | } @{$o_tables->list_from_schema($s_schema)}]; | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | 2 | ▶ | sub primaries { | ||||||||||
|
Subroutine
primaries: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 101 | 2 | my ($self, $s_schema) = @_; | |||||||||||
| 102 | 2 | require Geoffrey::Action::Constraint::PrimaryKey; | |||||||||||
| 103 | return [ | ||||||||||||
| 104 | 2 | $self->map_entry( | |||||||||||
| 105 | Geoffrey::Action::Constraint::PrimaryKey->new(dbh => $self->dbh, converter => $self->converter) | ||||||||||||
| 106 | ->list_from_schema($s_schema))]; | ||||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | 2 | ▶ | sub uniques { | ||||||||||
|
Subroutine
uniques: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 110 | 2 | my ($self, $s_schema) = @_; | |||||||||||
| 111 | 2 | require Geoffrey::Action::Constraint::Unique; | |||||||||||
| 112 | return [ | ||||||||||||
| 113 | 2 | $self->map_entry( | |||||||||||
| 114 | Geoffrey::Action::Constraint::Unique->new(dbh => $self->dbh, converter => $self->converter) | ||||||||||||
| 115 | ->list_from_schema($s_schema))]; | ||||||||||||
| 116 | } | ||||||||||||
| 117 | |||||||||||||
| 118 | 2 | ▶ | sub foreigns { | ||||||||||
|
Subroutine
foreigns: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 119 | 2 | my ($self, $s_schema) = @_; | |||||||||||
| 120 | 2 | my $count = 1; | |||||||||||
| 121 | 2 | require Geoffrey::Action::Constraint::ForeignKey; | |||||||||||
| 122 | 2 | my $o_foreign_keys | |||||||||||
| 123 | = Geoffrey::Action::Constraint::ForeignKey->new(dbh => $self->dbh, converter => $self->converter); | ||||||||||||
| 124 | 0 | return [map { $self->map_entry([$_], $count++) } @{$o_foreign_keys->list_from_schema($s_schema)}]; | |||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | 2 | ▶ | sub indexes { | ||||||||||
|
Subroutine
indexes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 128 | 2 | my ($self, $s_schema) = @_; | |||||||||||
| 129 | 2 | require Geoffrey::Action::Constraint::Index; | |||||||||||
| 130 | return [ | ||||||||||||
| 131 | 2 | $self->map_entry( | |||||||||||
| 132 | Geoffrey::Action::Constraint::Index->new(converter => $self->converter, dbh => $self->dbh) | ||||||||||||
| 133 | ->list_from_schema($s_schema))]; | ||||||||||||
| 134 | } | ||||||||||||
| 135 | |||||||||||||
| 136 | 2 | ▶ | sub views { | ||||||||||
|
Subroutine
views: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 137 | 2 | my ($self, $s_schema) = @_; | |||||||||||
| 138 | 2 | require Geoffrey::Action::View; | |||||||||||
| 139 | return [ | ||||||||||||
| 140 | 2 | $self->map_entry( | |||||||||||
| 141 | Geoffrey::Action::View->new(converter => $self->converter, dbh => $self->dbh) | ||||||||||||
| 142 | ->list_from_schema($s_schema), | ||||||||||||
| 143 | 1 | ||||||||||||
| 144 | )]; | ||||||||||||
| 145 | } | ||||||||||||
| 146 | |||||||||||||
| 147 | 3 | ▶ | sub functions { | ||||||||||
|
Subroutine
functions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 148 | 3 | my ($self, $s_schema) = @_; | |||||||||||
| 149 | 3 | my $count = 1; | |||||||||||
| 150 | 3 | require Geoffrey::Action::Function; | |||||||||||
| 151 | 3 | my $o_functions = Geoffrey::Action::Function->new(dbh => $self->dbh, converter => $self->converter); | |||||||||||
| 152 | 3 | return [map { $self->map_entry([$_], $count++) } @{$o_functions->list($s_schema)}]; | |||||||||||
| 153 | } | ||||||||||||
| 154 | |||||||||||||
| 155 | 3 | ▶ | sub triggers { | ||||||||||
|
Subroutine
triggers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 156 | 3 | my ($self, $s_schema) = @_; | |||||||||||
| 157 | 3 | my $count = 1; | |||||||||||
| 158 | 3 | require Geoffrey::Action::Trigger; | |||||||||||
| 159 | 3 | my $o_trigger = Geoffrey::Action::Trigger->new(dbh => $self->dbh, converter => $self->converter); | |||||||||||
| 160 | 3 | return [map { $self->map_entry([$_], $count++) } @{$o_trigger->list($s_schema)}]; | |||||||||||
| 161 | } | ||||||||||||
| 162 | |||||||||||||
| 163 | 18 | ▶ | sub map_entry { | ||||||||||
|
Subroutine
map_entry: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 164 | 18 | my ($self, $ar_entries, $i_count) = @_; | |||||||||||
| 165 | 18 | return {id => $self->changeset_id($i_count), author => $self->author, entries => $ar_entries,}; | |||||||||||
| 166 | } | ||||||||||||
| 167 | |||||||||||||
| 168 | 3 | 1; # End of Geoffrey::Read | |||||||||||
| 169 | |||||||||||||
| 170 | __END__ | ||||||||||||