Schema/ResultSet/UriRedirect.pm

filter: Statementstmt 100% 25 / 25 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 100% 40 / 40 CC 5 SCAR 11.0
CC
5
Cov
100%
redirect
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« Schema/ResultSet/Product.pm ↑ Summary Schema/Result/Navigation.pm »
1 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Interchange6::Schema::ResultSet::UriRedirect;
4  
5 =head1 NAME
6  
7 Interchange6::Schema::ResultSet::UriRedirect
8  
9 =cut
10  
11 =head1 SYNOPSIS
12  
13 Provides extra accessor methods for L<Interchange6::Schema::Result::UriRedirect>
14  
15 =cut
16  
17 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use parent 'Interchange6::Schema::ResultSet';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 =head1 METHODS
24  
25 =head2 redirect( $source_uri )
26  
27 Find L<Interchange6::Schema::Result::UriRedirect/uri_source> and check
28 for circular redirects. In the event that a non-circular chain of redirects
29 is found the last item found is returned.
30  
31 Returns depend on what is found:
32  
33 =over 4
34  
35 =item C<$source_uri> is not found
36  
37 Returns undef.
38  
39 =item Circular redirect found
40  
41 Returns undef.
42  
43 =item Normal redirect found
44  
45 Returns the corresponding
46 L<Interchange6::Schema::Result::UriRedirect/uri_target> and
47 L<Interchange6::Schema::Result::UriRedirect/status_code> as an array
48 in list context or as an array reference in scalar context.
49  
50 =back
51  
52 =cut
53  
54 sub redirect {
55 4 ▶ my $self = shift;
Subroutine redirect: called CC=5 SCAR=16.1
Pod documented
56 4 my $uri_source = shift;
57  
58 4 my $result = $self->find( { uri_source => $uri_source } );
59  
60 4 ▶ return undef unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 1 3 4
61  
62 3 ▶ while ( my $next = $self->find( { uri_source => $result->uri_target } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = $self->find({"uri_source", $result->uri_target})) 4 2 6
63 {
64 # return on circular redirect
65 4 ▶ return undef if $uri_source eq $next->uri_target;
Branch: 1 branch
BranchTrueFalseTotal
if $uri_source eq $next->uri_target 1 3 4
66 3 $result = $next;
67 }
68  
69 2 my @ret = ( $result->uri_target, $result->status_code );
70  
71 2 ▶ return wantarray ? @ret : \@ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
72 }
73  
74 2 1;
« Schema/ResultSet/Product.pm ↑ Summary Schema/Result/Navigation.pm »