1DBIx::Class::Helpers::UUtsielr(3C)ontributed Perl DocumeDnBtIaxt:i:oCnlass::Helpers::Util(3)
2
3
4
6 DBIx::Class::Helpers::Util - Helper utilities for DBIx::Class
7 components
8
10 use DBIx::Class::Helpers::Util ':all';
11
12 my ($namespace, $class) = get_namespace_parts('MyApp:Schema::Person');
13 is $namespace, 'MyApp::Schema';
14 is $class, 'Person';
15
16 if (is_load_namespaces('MyApp::Schema::Result::Person')) {
17 print 'correctly structured project';
18 }
19
20 if (is_not_load_namespaces('MyApp::Schema::Person')) {
21 print 'incorrectly structured project';
22 }
23
24 if (assert_similar_namespaces('MyApp::Schema::Person', 'FooApp::Schema::People')) {
25 print 'both projects are structured similarly';
26 }
27
28 if (assert_similar_namespaces('MyApp::Schema::Result::Person', 'FooApp::Schema::Result::People')) {
29 print 'both projects are structured similarly';
30 }
31
32 # in a resultset
33
34 sub search {
35 my ($self, $search, $attrs) = @_;
36
37 $attrs->{order_by} = order_by_visitor($attrs->{order_by}, sub {
38 my $field = shift;
39
40 return 'foo_bar' if $field eq 'foo.bar';
41 return $field;
42 }) if $attrs && $attrs->{order_by};
43
44 $self->next::method($search, $attrs);
45 }
46
47 # in schema
48
49 sub connection {
50 my $self = shift;
51
52 my $args = normalize_connect_info(@_);
53 $args->{quote_names} = 1;
54
55 $self->next::method($args)
56 }
57
59 A collection of various helper utilities for DBIx::Class stuff.
60 Probably only useful for components.
61
63 order_by_visitor
64 This function allows you to easily transform "order_by" clauses. See
65 "SYNOPSIS" for example.
66
67 get_namespace_parts
68 Returns the namespace and class name of a package. See "SYNOPSIS" for
69 example.
70
71 is_load_namespaces
72 Returns true if a package is structured in a way that would work for
73 load_namespaces. See "SYNOPSIS" for example.
74
75 is_not_load_namespaces
76 Returns true if a package is structured in a way that would not work
77 for load_namespaces. See "SYNOPSIS" for example.
78
79 assert_similar_namespaces
80 Dies if both packages are structured in the same way. The same means
81 both are load_namespaces or both are not. See "SYNOPSIS" for example.
82
83 normalize_connect_info
84 Takes all of the various and interesting forms that can be passed to
85 connect and normalizes them into the final and simplest form, a single
86 hashref.
87
89 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
90
92 This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
93
94 This is free software; you can redistribute it and/or modify it under
95 the same terms as the Perl 5 programming language system itself.
96
97
98
99perl v5.36.0 2023-01-20 DBIx::Class::Helpers::Util(3)