« blib/lib/DBIO/PostgreSQL/Introspect/Columns.pm
↑ Summary
blib/lib/DBIO/PostgreSQL/Introspect/Types.pm »
| 1 | package DBIO::PostgreSQL::Introspect::Functions; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Introspect PostgreSQL functions | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 171 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 171 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 171 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 171 | ▶ | use DBIO::PostgreSQL::Introspect (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 0 | my ($class, $dbh, $filter) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | my $sql = q{ | |||||||||||||||||||||||||||
| 17 | SELECT | ||||||||||||||||||||||||||||
| 18 | n.nspname AS schema_name, | ||||||||||||||||||||||||||||
| 19 | p.proname AS function_name, | ||||||||||||||||||||||||||||
| 20 | p.prokind AS kind, | ||||||||||||||||||||||||||||
| 21 | p.oid AS function_oid, | ||||||||||||||||||||||||||||
| 22 | pg_catalog.pg_get_function_identity_arguments(p.oid) AS identity_args, | ||||||||||||||||||||||||||||
| 23 | (SELECT COALESCE(pg_catalog.string_agg(pg_catalog.format_type(u.t, NULL), ',' ORDER BY u.ord), '') | ||||||||||||||||||||||||||||
| 24 | FROM pg_catalog.unnest(p.proargtypes::pg_catalog.oid[]) WITH ORDINALITY AS u(t, ord)) AS input_types, | ||||||||||||||||||||||||||||
| 25 | CASE WHEN p.prokind IN ('f', 'p') | ||||||||||||||||||||||||||||
| 26 | THEN pg_catalog.pg_get_functiondef(p.oid) END AS definition, | ||||||||||||||||||||||||||||
| 27 | CASE p.prokind | ||||||||||||||||||||||||||||
| 28 | WHEN 'a' THEN ( | ||||||||||||||||||||||||||||
| 29 | SELECT pg_catalog.concat_ws('|', | ||||||||||||||||||||||||||||
| 30 | ag.aggkind, ag.aggnumdirectargs::text, | ||||||||||||||||||||||||||||
| 31 | ag.aggtransfn::pg_catalog.oid::pg_catalog.regprocedure::text, | ||||||||||||||||||||||||||||
| 32 | ag.aggfinalfn::pg_catalog.oid::pg_catalog.regprocedure::text, | ||||||||||||||||||||||||||||
| 33 | ag.aggcombinefn::pg_catalog.oid::pg_catalog.regprocedure::text, | ||||||||||||||||||||||||||||
| 34 | ag.aggserialfn::pg_catalog.oid::pg_catalog.regprocedure::text, | ||||||||||||||||||||||||||||
| 35 | ag.aggdeserialfn::pg_catalog.oid::pg_catalog.regprocedure::text, | ||||||||||||||||||||||||||||
| 36 | ag.aggmtransfn::pg_catalog.oid::pg_catalog.regprocedure::text, | ||||||||||||||||||||||||||||
| 37 | ag.aggminvtransfn::pg_catalog.oid::pg_catalog.regprocedure::text, | ||||||||||||||||||||||||||||
| 38 | ag.aggmfinalfn::pg_catalog.oid::pg_catalog.regprocedure::text, | ||||||||||||||||||||||||||||
| 39 | ag.aggfinalextra::text, ag.aggmfinalextra::text, | ||||||||||||||||||||||||||||
| 40 | ag.aggfinalmodify::text, ag.aggmfinalmodify::text, | ||||||||||||||||||||||||||||
| 41 | ag.aggsortop::pg_catalog.oid::pg_catalog.regoperator::text, | ||||||||||||||||||||||||||||
| 42 | pg_catalog.format_type(ag.aggtranstype, NULL), | ||||||||||||||||||||||||||||
| 43 | ag.aggtransspace::text, | ||||||||||||||||||||||||||||
| 44 | COALESCE(pg_catalog.format_type(NULLIF(ag.aggmtranstype, 0), NULL), ''), | ||||||||||||||||||||||||||||
| 45 | ag.aggmtransspace::text, | ||||||||||||||||||||||||||||
| 46 | COALESCE(ag.agginitval, '<null>'), COALESCE(ag.aggminitval, '<null>'), | ||||||||||||||||||||||||||||
| 47 | p.provolatile::text, p.proparallel::text, p.proisstrict::text, | ||||||||||||||||||||||||||||
| 48 | pg_catalog.format_type(p.prorettype, NULL)) | ||||||||||||||||||||||||||||
| 49 | FROM pg_catalog.pg_aggregate ag WHERE ag.aggfnoid = p.oid) | ||||||||||||||||||||||||||||
| 50 | WHEN 'w' THEN pg_catalog.concat_ws('|', | ||||||||||||||||||||||||||||
| 51 | l.lanname, COALESCE(p.prosrc, ''), COALESCE(p.probin, ''), | ||||||||||||||||||||||||||||
| 52 | p.provolatile::text, p.proparallel::text, p.proisstrict::text, | ||||||||||||||||||||||||||||
| 53 | pg_catalog.format_type(p.prorettype, NULL)) | ||||||||||||||||||||||||||||
| 54 | END AS fingerprint, | ||||||||||||||||||||||||||||
| 55 | l.lanname AS language, | ||||||||||||||||||||||||||||
| 56 | p.provolatile AS volatility, | ||||||||||||||||||||||||||||
| 57 | p.proisstrict AS is_strict, | ||||||||||||||||||||||||||||
| 58 | p.prosecdef AS security_definer, | ||||||||||||||||||||||||||||
| 59 | pg_catalog.format_type(p.prorettype, NULL) AS return_type | ||||||||||||||||||||||||||||
| 60 | FROM pg_catalog.pg_proc p | ||||||||||||||||||||||||||||
| 61 | JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace | ||||||||||||||||||||||||||||
| 62 | JOIN pg_catalog.pg_language l ON l.oid = p.prolang | ||||||||||||||||||||||||||||
| 63 | WHERE 1=1 | ||||||||||||||||||||||||||||
| 64 | AND p.prokind IN ('f', 'p', 'a', 'w') | ||||||||||||||||||||||||||||
| 65 | }; | ||||||||||||||||||||||||||||
| 66 | 0 | $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('n'); | |||||||||||||||||||||||||||
| 67 | 0 | $sql .= DBIO::PostgreSQL::Introspect->extension_member_filter('pg_proc', 'p.oid'); | |||||||||||||||||||||||||||
| 68 | 0 | $sql .= DBIO::PostgreSQL::Introspect->internal_part_filter('pg_proc', 'p.oid'); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | my @bind; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ($filter && @$filter) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filter and @$filter
MC/DC0%0/2
$filter and @$filter
$filter
@$filter
Truth table0%0/3
A and B
A= $filterB= @$filter
| |||||||||||||||||||||||||||||
| 72 | 0 | $sql .= ' AND n.nspname = ANY($1)'; | |||||||||||||||||||||||||||
| 73 | 0 | push @bind, $filter; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | $sql .= ' ORDER BY n.nspname, p.proname'; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||||||||||||||||||
| 79 | 0 | $sth->execute(@bind); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | my %functions; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | my $key = "$row->{schema_name}.$row->{function_name}($row->{identity_args})"; | |||||||||||||||||||||||||||
| 84 | $functions{$key} = { | ||||||||||||||||||||||||||||
| 85 | schema_name => $row->{schema_name}, | ||||||||||||||||||||||||||||
| 86 | function_name => $row->{function_name}, | ||||||||||||||||||||||||||||
| 87 | kind => $row->{kind}, | ||||||||||||||||||||||||||||
| 88 | identity_args => $row->{identity_args}, | ||||||||||||||||||||||||||||
| 89 | input_types => $row->{input_types}, | ||||||||||||||||||||||||||||
| 90 | definition => $row->{definition}, | ||||||||||||||||||||||||||||
| 91 | ( defined $row->{fingerprint} ? (fingerprint => $row->{fingerprint}) : () ), | ||||||||||||||||||||||||||||
| 92 | language => $row->{language}, | ||||||||||||||||||||||||||||
| 93 | volatility => $row->{volatility}, | ||||||||||||||||||||||||||||
| 94 | is_strict => $row->{is_strict} ? 1 : 0, | ||||||||||||||||||||||||||||
| 95 | security_definer => $row->{security_definer} ? 1 : 0, | ||||||||||||||||||||||||||||
| 96 | return_type => $row->{return_type}, | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | }; | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | return \%functions; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 171 | 1; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||