| 1 | 2 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | package DBIx::Class::Smooth::Schema; | ||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | # ABSTRACT: Short intro | ||||||||||||||||||||||||||||||||||||
| 8 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.0105'; | |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use parent 'DBIx::Class::Schema'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use experimental qw/postderef signatures/; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | 2 | our $dbix_class_smooth_methods_created = 0; | |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | ▶ | sub connection($self, @rest) { | |||||||||||||||||||||||||||||||||||
|
Subroutine
connection: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 19 | 0 | $self = $self->next::method(@rest); | |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if(!$dbix_class_smooth_methods_created) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 22 | 0 | $self->_dbix_class_smooth_create_methods(); | |||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||
| 24 | 0 | return $self; | |||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | ▶ | sub _dbix_class_smooth_create_methods($self) { | |||||||||||||||||||||||||||||||||||
|
Subroutine
_dbix_class_smooth_create_methods: not called CC=3 SCAR=21.9
| |||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 29 | 0 | for my $source (sort $self->sources) { | |||||||||||||||||||||||||||||||||||
| 30 | 0 | (my $method = $source) =~ s{::}{_}g; | |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if($self->can($method)) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 33 | 0 | croak(caller(1) . " already has a method named <$method>."); | |||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | 0 | *{ caller(1) . "::$method" } = sub { | |||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my $rs = shift->resultset($source); | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | return !scalar @_ ? $rs | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
defined $_[0] and not ref $_[0]
MC/DC0%0/2
defined $_[0] and not ref $_[0]
defined $_[0]
not ref $_[0]
Truth table0%0/3
A and not(B)
A= defined $_[0]B= not ref $_[0]
| |||||||||||||||||||||||||||||||||||||
| 40 | : defined $_[0] && !ref $_[0] ? $rs->find(@_) | ||||||||||||||||||||||||||||||||||||
| 41 | : ref $_[0] eq 'ARRAY' ? $rs->find(@$_[1..$#_], { key => $_->[0] }) | ||||||||||||||||||||||||||||||||||||
| 42 | : $rs->search(@_) | ||||||||||||||||||||||||||||||||||||
| 43 | ; | ||||||||||||||||||||||||||||||||||||
| 44 | 0 | }; | |||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||
| 46 | 0 | $dbix_class_smooth_methods_created = 1; | |||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||
| 50 | 2 | 1; | |||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||
| 54 | =pod | ||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||
| 56 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | DBIx::Class::Smooth::Schema - Short intro | ||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||
| 62 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | Version 0.0105, released 2020-09-20. | ||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||
| 66 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||
| 68 | # in MyApp::Schema, instead of inheriting from DBIx::Class::Schema | ||||||||||||||||||||||||||||||||||||
| 69 | use parent 'DBIx::Class::Smooth::Schema'; | ||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||
| 73 | DBIx::Class::Smooth::Schema adds method accessors for all resultsets. | ||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||
| 75 | In short, instead of this: | ||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||
| 77 | my $schema = MyApp::Schema->connect(...); | ||||||||||||||||||||||||||||||||||||
| 78 | my $result = $schema->resultset('Author'); | ||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||
| 80 | You can do this: | ||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||
| 82 | my $schema = MyApp::Schema->connect(...); | ||||||||||||||||||||||||||||||||||||
| 83 | my $result = $schema->Author; | ||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||
| 85 | =head2 What is returned? | ||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||
| 87 | The resultset methods can be called in four different ways. | ||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||
| 89 | =head3 Without arguments | ||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||
| 91 | # $schema->resultset('Author') | ||||||||||||||||||||||||||||||||||||
| 92 | $schema->Author; | ||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||
| 94 | =head3 With a scalar | ||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | # $schema->resultset('Author')->find(5) | ||||||||||||||||||||||||||||||||||||
| 97 | $schema->Author(5); | ||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||
| 99 | =head3 With an array reference | ||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||
| 101 | # $schema->resultset('Book')->find({ author => 'J.R.R Tolkien', title => 'The Hobbit' }, { key => 'book_author_title' }); | ||||||||||||||||||||||||||||||||||||
| 102 | $schema->Book([book_author_title => { author => 'J.R.R Tolkien', title => 'The Hobbit' }]); | ||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||
| 104 | =head3 With anything else | ||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | # $schema->resultset('Author')->search({ last_name => 'Tolkien'}, { order_by => { -asc => 'first_name' }}); | ||||||||||||||||||||||||||||||||||||
| 107 | $schema->Author({ last_name => 'Tolkien'}, { order_by => { -asc => 'first_name' }}); | ||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||
| 109 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||
| 111 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||
| 113 | =item * | ||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | L<DBIx::Class::Smooth> | ||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||
| 117 | =back | ||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||
| 119 | =head1 SOURCE | ||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||
| 121 | L<https://github.com/Csson/p5-DBIx-Class-Smooth> | ||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||
| 123 | =head1 HOMEPAGE | ||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||
| 125 | L<https://metacpan.org/release/DBIx-Class-Smooth> | ||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||
| 129 | Erik Carlsson <info@code301.com> | ||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||
| 131 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||
| 133 | This software is copyright (c) 2018 by Erik Carlsson. | ||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||
| 135 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||
| 136 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||||||||||