blib/lib/Dallycot/TextResolver.pm

filter: Statementstmt 76.9% 40 / 52 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.2% 13 / 16 Podpod 0.0% 0 / 1 totaltotal 74.6% 53 / 71 CC 2 SCAR 5.3
CC
2
Cov
74%
get
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.7
« blib/lib/Dallycot/AST/Condition.pm ↑ Summary blib/lib/Dallycot/Value/ClosedRange.pm »
1 package Dallycot::TextResolver;
2 10 our $AUTHORITY = 'cpan:JSMITH';
3  
4 # ABSTRACT: Resolve URLs into text objects
5  
6 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use experimental qw(switch);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 ▶use MooseX::Singleton;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 10 ▶use CHI;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use Promises qw(deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 ▶use RDF::Trine::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 10 ▶use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 10 ▶use Dallycot::TextResolver::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 has cache => (
24 is => 'ro',
25 default => sub {
26 1 ▶ CHI->new( driver => 'Memory', cache_size => '32M', datastore => {} );
Subroutine __ANON__: called CC=1 SCAR=0.0
27 }
28 10 );
29  
30 has ua => (
31 is => 'ro',
32 default => sub {
33 1 ▶ Mojo::UserAgent->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
34 }
35 10 );
36  
37 sub get {
38 0 ▶ my ( $self, $url ) = @_;
Subroutine get: not called CC=2 SCAR=17.9
Pod undocumented
39  
40 0 my $deferred = deferred;
41  
42 0 my $data = $self->cache->get($url);
43 0 ▶ if ( defined($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) { } 0 0 0
44 0 $deferred->resolve($data);
45 }
46 else {
47 0 my $request = Dallycot::TextResolver::Request->new(
48 ua => $self->ua,
49 url => $url,
50 canonical_url => $url,
51 );
52 $request->run->done(
53 sub {
54 0 ▶ ($data) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 $self->cache->set( $url, $data );
56 0 $deferred->resolve($data);
57 },
58 sub {
59 0 ▶ $deferred->reject(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 }
61 0 );
62 }
63  
64 0 return $deferred->promise;
65 }
66  
67 10 __PACKAGE__->meta->make_immutable;
68  
69 10 1;
« blib/lib/Dallycot/AST/Condition.pm ↑ Summary blib/lib/Dallycot/Value/ClosedRange.pm »