| 1 | package DBIx::Class::Helper::ResultSet::Errors; | ||||||||||||||||||||
| 2 | 54 | $DBIx::Class::Helper::ResultSet::Errors::VERSION = '2.033001'; | |||||||||||||||||||
| 3 | # ABSTRACT: add exceptions to help when calling Result methods on an ResultSets | ||||||||||||||||||||
| 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::ResultSet'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 54 | my $std_err = qq{Can't locate object method "%s" via package "%s" } . | |||||||||||||||||||
| 11 | qq{at %s line %d.\n}; | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 54 | my $cust_err = qq{You're trying to call a Result ("%s") method ("%s") } . | |||||||||||||||||||
| 14 | qq{on a ResultSet ("%s") at %s line %d.\n}; | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub AUTOLOAD { | ||||||||||||||||||||
| 17 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=15.2
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | ▶ | my($class) = ref $self || $self; | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | my($meth) = $DBIx::Class::Helper::ResultSet::Errors::AUTOLOAD | |||||||||||||||||||
| 22 | =~ m/::([^:]+)$/; | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | ▶ | return if $meth eq 'DESTROY'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 1 | my($callpack, $callfile, $callline) = caller; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | my $rclass = $self->result_source->result_class; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | ▶ | die sprintf $cust_err, $rclass, $meth, $class, $callfile, $callline | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | if $rclass->can($meth); | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | die sprintf $std_err, $meth, $class, $callfile, $callline; | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 54 | 1; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | __END__ | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =pod | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =head1 NAME | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | DBIx::Class::Helper::ResultSet::Errors - add exceptions to help when calling Result methods on an ResultSets | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =head1 SYNOPSIS | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | package MyApp::Schema::ResultSet::Foo; | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | __PACKAGE__->load_components(qw{Helper::ResultSet::Errors}); | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | ... | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 1; | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | And then in a script or something: | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | my $col = $rs->id | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | # dies with a helpful error! | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =head1 DESCRIPTION | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | Users new to C<DBIx::Class> often make the mistake of treating ResultSets like | ||||||||||||||||||||
| 65 | Results. This helper ameliorates the situation by giving a helpful error when | ||||||||||||||||||||
| 66 | the user calls methods for the result on the ResultSet. See | ||||||||||||||||||||
| 67 | L<DBIx::Class::Helper::ResultSet/NOTE> for a nice way to apply it to your entire | ||||||||||||||||||||
| 68 | schema. | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head1 AUTHOR | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | This software is copyright (c) 2016 by Arthur Axel "fREW" Schmidt. | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 79 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||