PostgreSQL/Diff/Function.pm

filter: Statementstmt 100% 38 / 38 Branchbran 94.4% 17 / 18 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 93.4% 71 / 76 CC 15 SCAR 17.3
CC
15
Cov
95%
diff
8.0
as_sql
6.0
summary
3.0
CRAP 5.6
« PostgreSQL/Diff/Table.pm ↑ Summary PostgreSQL/Adapter.pm »
1 package DBIO::PostgreSQL::Diff::Function;
2 # ABSTRACT: Diff operations for PostgreSQL functions
3  
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 __PACKAGE__->mk_diff_accessors(qw(function_key function_info));
10  
11  
12  
13  
14  
15 7 ▶sub diff {
Subroutine diff: called CC=8 SCAR=20.8
Pod documented
16 7 my ($class, $source, $target) = @_;
17 7 my @ops;
18  
19 7 for my $key (sort keys %$target) {
20 7 ▶ if (!exists $source->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $source->{$key}) 5 2 7
21 push @ops, $class->new(
22 action => 'create',
23 function_key => $key,
24 5 function_info => $target->{$key},
25 );
26 5 next;
27 }
28 # Compare definitions
29 2 ▶ my $src_def = $source->{$key}{definition} // '';
Condition50%1/2
$source->{$key}{"definition"} // ""
l!l
20
MC/DC0%0/1
$source->{$key}{"definition"} // ""
$source->{$key}{"definition"}
Truth table50%1/2
A
A= $source->{$key}{"definition"}
Aresult
11
00
30 2 ▶ my $tgt_def = $target->{$key}{definition} // '';
Condition50%1/2
$target->{$key}{"definition"} // ""
l!l
20
MC/DC0%0/1
$target->{$key}{"definition"} // ""
$target->{$key}{"definition"}
Truth table50%1/2
A
A= $target->{$key}{"definition"}
Aresult
11
00
31 2 ▶ if ($src_def ne $tgt_def) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src_def ne $tgt_def) 1 1 2
32 push @ops, $class->new(
33 action => 'replace',
34 function_key => $key,
35 1 function_info => $target->{$key},
36 );
37 }
38 }
39  
40 7 for my $key (sort keys %$source) {
41 4 ▶ next if exists $target->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $target->{$key} 2 2 4
42 push @ops, $class->new(
43 action => 'drop',
44 function_key => $key,
45 2 function_info => $source->{$key},
46 );
47 }
48  
49 7 return @ops;
50 }
51  
52  
53 7 ▶sub as_sql {
Subroutine as_sql: called CC=6 SCAR=17.9
Pod documented
54 7 my ($self) = @_;
55 7 my $info = $self->function_info;
56  
57 7 ▶ if ($self->action eq 'create' || $self->action eq 'replace') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->action eq 'create' or $self->action eq 'replace') { } 6 1 7
elsif ($self->action eq 'drop') { } 1 0 1
Condition100%3/3
$self->action eq "create" or $self->action eq "replace"
l!l&&r!l&&!r
511
MC/DC100%2/2
$self->action eq "create" or $self->action eq "replace"
$self->action eq "create" $self->action eq "replace"
Truth table100%3/3
A or B
A= $self->action eq "create"B= $self->action eq "replace"
ABresult
1X1
011
000
58 6 ▶ if ($info->{definition}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"definition"}) 5 1 6
59 5 my $def = $info->{definition};
60 5 $def =~ s/\s*$//;
61 5 ▶ $def .= ';' unless $def =~ /;\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $def =~ /;\s*$/ 3 2 5
62 5 return $def;
63 }
64 1 return sprintf '-- CREATE OR REPLACE FUNCTION %s (definition unavailable)', $self->function_key;
65 }
66 elsif ($self->action eq 'drop') {
67 1 return sprintf 'DROP FUNCTION %s;', $self->function_key;
68 }
69 }
70  
71  
72 3 ▶sub summary {
Subroutine summary: called CC=3 SCAR=11.0
Pod documented
73 3 my ($self) = @_;
74 3 ▶ my $prefix = $self->action eq 'create' ? '+' : $self->action eq 'drop' ? '-' : '~';
Branch: 2 branches
BranchTrueFalseTotal
$self->action eq 'create' ? : 1 2 3
$self->action eq 'drop' ? : 1 1 2
75 3 return sprintf ' %sfunction: %s', $prefix, $self->function_key;
76 }
77  
78 9 1;
79  
80 __END__
81  
82 =pod
83  
84 =encoding UTF-8
85  
86 =head1 NAME
87  
88 DBIO::PostgreSQL::Diff::Function - Diff operations for PostgreSQL functions
89  
90 =head1 VERSION
91  
92 version 0.900001
93  
94 =head1 DESCRIPTION
95  
96 Represents a function-level diff operation: C<CREATE FUNCTION>, C<DROP
97 FUNCTION>, or C<CREATE OR REPLACE FUNCTION> (when the definition has changed).
98 Function identity is by the full signature key C<schema.name(identity_args)>.
99  
100 =head1 ATTRIBUTES
101  
102 =head2 function_key
103  
104 The function's identity string: C<schema.name(args)>.
105  
106 =head2 function_info
107  
108 Function metadata hashref (C<definition>, C<language>, C<return_type>, etc.).
109  
110 =head1 METHODS
111  
112 =head2 diff
113  
114 my @ops = DBIO::PostgreSQL::Diff::Function->diff($source, $target);
115  
116 Compares function hashrefs by identity key. Produces C<create>, C<replace>
117 (definition changed), or C<drop> operations.
118  
119 =head2 as_sql
120  
121 Returns the SQL. For C<create> and C<replace>, emits the full function
122 definition from introspection. For C<drop>, returns C<DROP FUNCTION key;>.
123  
124 =head2 summary
125  
126 Returns a one-line description such as C<+function: auth.update_modified_at()>.
127  
128 =head1 AUTHOR
129  
130 DBIO & DBIx::Class Authors
131  
132 =head1 COPYRIGHT AND LICENSE
133  
134 Copyright (C) 2026 DBIO Authors
135 Portions Copyright (C) 2005-2025 DBIx::Class Authors
136 Based on DBIx::Class, heavily modified.
137  
138 This is free software; you can redistribute it and/or modify it under
139 the same terms as the Perl 5 programming language system itself.
140  
141 =cut
« PostgreSQL/Diff/Table.pm ↑ Summary PostgreSQL/Adapter.pm »