| 1 | package DBIO::PostgreSQL::Introspect::Functions; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Introspect PostgreSQL functions | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use DBIO::PostgreSQL::Introspect (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 0 | my ($class, $dbh, $filter) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | my $sql = q{ | |||||||||||||||||||||||||||
| 15 | SELECT | ||||||||||||||||||||||||||||
| 16 | n.nspname AS schema_name, | ||||||||||||||||||||||||||||
| 17 | p.proname AS function_name, | ||||||||||||||||||||||||||||
| 18 | p.oid AS function_oid, | ||||||||||||||||||||||||||||
| 19 | pg_catalog.pg_get_function_identity_arguments(p.oid) AS identity_args, | ||||||||||||||||||||||||||||
| 20 | pg_catalog.pg_get_functiondef(p.oid) AS definition, | ||||||||||||||||||||||||||||
| 21 | l.lanname AS language, | ||||||||||||||||||||||||||||
| 22 | p.provolatile AS volatility, | ||||||||||||||||||||||||||||
| 23 | p.proisstrict AS is_strict, | ||||||||||||||||||||||||||||
| 24 | p.prosecdef AS security_definer, | ||||||||||||||||||||||||||||
| 25 | pg_catalog.format_type(p.prorettype, NULL) AS return_type | ||||||||||||||||||||||||||||
| 26 | FROM pg_catalog.pg_proc p | ||||||||||||||||||||||||||||
| 27 | JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace | ||||||||||||||||||||||||||||
| 28 | JOIN pg_catalog.pg_language l ON l.oid = p.prolang | ||||||||||||||||||||||||||||
| 29 | WHERE 1=1 | ||||||||||||||||||||||||||||
| 30 | AND p.prokind IN ('f', 'p') | ||||||||||||||||||||||||||||
| 31 | }; | ||||||||||||||||||||||||||||
| 32 | 0 | $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('n'); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my @bind; | |||||||||||||||||||||||||||
| 35 | 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
| |||||||||||||||||||||||||||||
| 36 | 0 | $sql .= ' AND n.nspname = ANY($1)'; | |||||||||||||||||||||||||||
| 37 | 0 | push @bind, $filter; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | $sql .= ' ORDER BY n.nspname, p.proname'; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||||||||||||||||||
| 43 | 0 | $sth->execute(@bind); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my %functions; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | my $key = "$row->{schema_name}.$row->{function_name}($row->{identity_args})"; | |||||||||||||||||||||||||||
| 48 | $functions{$key} = { | ||||||||||||||||||||||||||||
| 49 | schema_name => $row->{schema_name}, | ||||||||||||||||||||||||||||
| 50 | function_name => $row->{function_name}, | ||||||||||||||||||||||||||||
| 51 | identity_args => $row->{identity_args}, | ||||||||||||||||||||||||||||
| 52 | definition => $row->{definition}, | ||||||||||||||||||||||||||||
| 53 | language => $row->{language}, | ||||||||||||||||||||||||||||
| 54 | volatility => $row->{volatility}, | ||||||||||||||||||||||||||||
| 55 | is_strict => $row->{is_strict} ? 1 : 0, | ||||||||||||||||||||||||||||
| 56 | security_definer => $row->{security_definer} ? 1 : 0, | ||||||||||||||||||||||||||||
| 57 | return_type => $row->{return_type}, | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | }; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | return \%functions; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 15 | 1; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =pod | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 NAME | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | DBIO::PostgreSQL::Introspect::Functions - Introspect PostgreSQL functions | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head1 VERSION | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | version 0.900001 | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Fetches function and procedure metadata from C<pg_catalog.pg_proc>. The full | ||||||||||||||||||||||||||||
| 83 | function definition is retrieved via C<pg_get_functiondef>. System functions | ||||||||||||||||||||||||||||
| 84 | (in C<pg_*> and C<information_schema> schemas) are excluded. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 METHODS | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head2 fetch | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | my $functions = DBIO::PostgreSQL::Introspect::Functions->fetch($dbh, $filter); | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | Returns a hashref keyed by C<schema.function_name(identity_args)>. Each entry | ||||||||||||||||||||||||||||
| 93 | has: C<schema_name>, C<function_name>, C<identity_args>, C<definition> (full | ||||||||||||||||||||||||||||
| 94 | source from C<pg_get_functiondef>), C<language>, C<volatility> (C<i>/C<s>/C<v>), | ||||||||||||||||||||||||||||
| 95 | C<is_strict>, C<security_definer>, C<return_type>. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | DBIO & DBIx::Class Authors | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||||||
| 104 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||||||||||||||||||
| 105 | Based on DBIx::Class, heavily modified. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 108 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||