PostgreSQL/Introspect/Schemas.pm

filter: Statementstmt 41.6% 10 / 24 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 36.8% 14 / 38 CC 4 SCAR 24.7
CC
4
Cov
32%
fetch
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 11.9
« PostgreSQL/Introspect/Triggers.pm ↑ Summary PostgreSQL/PgSchema.pm »
1 package DBIO::PostgreSQL::Introspect::Schemas;
2 # ABSTRACT: Introspect PostgreSQL schemas (namespaces)
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=4 SCAR=30.0
Pod documented
12 0 my ($class, $dbh, $filter) = @_;
13  
14 0 my $sql = q{
15 SELECT
16 n.nspname AS schema_name,
17 n.oid AS schema_oid,
18 pg_catalog.obj_description(n.oid, 'pg_namespace') AS comment
19 FROM pg_catalog.pg_namespace n
20 WHERE 1=1
21 };
22 0 $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('n');
23  
24 0 my @bind;
25 0 ▶ if ($filter && @$filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter and @$filter) 0 0 0
Condition0%0/3
$filter and @$filter
!ll&&!rl&&r
000
MC/DC0%0/2
$filter and @$filter
$filter @$filter
Truth table0%0/3
A and B
A= $filterB= @$filter
ABresult
0X0
100
111
26 0 $sql .= ' AND n.nspname = ANY($1)';
27 0 push @bind, $filter;
28 }
29  
30 0 $sql .= ' ORDER BY n.nspname';
31  
32 0 my $sth = $dbh->prepare($sql);
33 0 $sth->execute(@bind);
34  
35 0 my %schemas;
36 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
37 $schemas{ $row->{schema_name} } = {
38 oid => $row->{schema_oid},
39 comment => $row->{comment},
40 0 };
41 }
42  
43 0 return \%schemas;
44 }
45  
46 15 1;
47  
48 __END__
49  
50 =pod
51  
52 =encoding UTF-8
53  
54 =head1 NAME
55  
56 DBIO::PostgreSQL::Introspect::Schemas - Introspect PostgreSQL schemas (namespaces)
57  
58 =head1 VERSION
59  
60 version 0.900001
61  
62 =head1 DESCRIPTION
63  
64 Fetches PostgreSQL schema (namespace) metadata from C<pg_catalog.pg_namespace>.
65 System schemas (C<pg_*> and C<information_schema>) are excluded.
66  
67 =head1 METHODS
68  
69 =head2 fetch
70  
71 my $schemas = DBIO::PostgreSQL::Introspect::Schemas->fetch($dbh, $filter);
72  
73 Returns a hashref keyed by schema name. Each value is a hashref with keys
74 C<oid> and C<comment>. Pass an optional ArrayRef as C<$filter> to restrict
75 to specific schema names.
76  
77 =head1 AUTHOR
78  
79 DBIO & DBIx::Class Authors
80  
81 =head1 COPYRIGHT AND LICENSE
82  
83 Copyright (C) 2026 DBIO Authors
84 Portions Copyright (C) 2005-2025 DBIx::Class Authors
85 Based on DBIx::Class, heavily modified.
86  
87 This is free software; you can redistribute it and/or modify it under
88 the same terms as the Perl 5 programming language system itself.
89  
90 =cut
« PostgreSQL/Introspect/Triggers.pm ↑ Summary PostgreSQL/PgSchema.pm »