Helper/Schema/DidYouMean.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 95.3% 41 / 43 CC 3 SCAR 4.5
CC
3
Cov
94%
__ANON__
3.1
source
1.0
BEGIN
1.0
CRAP 1.6
« Helper/Schema/Verifier/RelationshipColumnName.pm ↑ Summary Helper/Schema/Verifier/Parent.pm »
1 package DBIx::Class::Helper::Schema::DidYouMean;
2 54 $DBIx::Class::Helper::Schema::DidYouMean::VERSION = '2.033001';
3 # ABSTRACT: Nice error messages when you misspell the name of a ResultSet
4  
5 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 54 ▶use parent 'DBIx::Class::Schema';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 54 ▶use Text::Brew 'distance';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 54 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 54 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub source {
15 1503 ▶ my ($self, @rest) = @_;
Subroutine source: called CC=1 SCAR=0.0
Pod documented
16  
17 1503 my $method = $self->next::can;
18  
19 try {
20 1503 ▶ $self->$method(@rest)
Subroutine __ANON__: called CC=1 SCAR=0.0
21 } catch {
22 1 ▶ if (m/Can't find source for (.+?) at/) {
Subroutine __ANON__: called CC=3 SCAR=11.3
Branch: 1 branch
BranchTrueFalseTotal
if (/Can't find source for (.+?) at/) 1 0 1
23 my @presentsources = map {
24 1 ▶ (distance($_, $1))[0] < 3 ? " * $_ <-- Possible Match\n" : " $_\n";
Branch: 1 branch
BranchTrueFalseTotal
(distance($_, $1))[0] < 3 ? : 1 9 10
25 } sort $self->storage->schema->sources;
26  
27 1 die <<"ERR";
28 $_
29 The ResultSet "$1" is not part of your schema.
30  
31 To help you debug this issue, here's a list of the actual sources that the
32 schema knows about:
33  
34 @presentsources
35 ERR
36 }
37 0 die $_;
38 }
39 1503 }
40  
41 54 1;
42  
43 __END__
44  
45 =pod
46  
47 =head1 NAME
48  
49 DBIx::Class::Helper::Schema::DidYouMean - Nice error messages when you misspell the name of a ResultSet
50  
51 =head1 SYNOPSIS
52  
53 package MyApp::Schema;
54  
55 __PACKAGE__->load_components('Helper::Schema::DidYouMean');
56  
57 Elsewhere:
58  
59 $schema->resultset('Usre')->search(...)->...
60  
61 And a nice exception gets thrown:
62  
63 The ResultSet "Usre" is not part of your schema.
64
65 To help you debug this issue, here's a list of the actual sources that the
66 schema knows about:
67
68 Account
69 Permission
70 Role
71 * User <-- Possible Match
72  
73 =head1 DESCRIPTION
74  
75 This helper captures errors thrown when you use the C<resultset> method on your
76 schema and typo the source name. It tries to highlight the best guess as to
77 which you meant to type.
78  
79 =head1 AUTHOR
80  
81 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
82  
83 =head1 COPYRIGHT AND LICENSE
84  
85 This software is copyright (c) 2016 by Arthur Axel "fREW" Schmidt.
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
« Helper/Schema/Verifier/RelationshipColumnName.pm ↑ Summary Helper/Schema/Verifier/Parent.pm »