File Coverage

blib/lib/RDF/DOAP/Utils.pm
Criterion Covered Total %
statement 21 33 63.6
branch 0 10 0.0
condition 0 6 0.0
subroutine 7 9 77.7
pod 0 1 0.0
total 28 59 47.4


line stmt bran cond sub pod time code
1             package RDF::DOAP::Utils;
2              
3             our $AUTHORITY = 'cpan:TOBYINK';
4             our $VERSION = '0.103';
5              
6 2     2   17 use strict;
  2         4  
  2         69  
7 2     2   12 use warnings;
  2         4  
  2         72  
8              
9 2     2   12 use RDF::DOAP::Types -types;
  2         4  
  2         26  
10 2     2   11852 use match::simple 'match';
  2         4387  
  2         16  
11 2     2   403 use List::Util 'uniq';
  2         6  
  2         272  
12              
13             use MooseX::AttributeTags (
14             WithURI => [
15             uri => [ is => 'ro', isa => Identifier, coerce => 1, required => 1 ],
16             multi => [ is => 'ro', isa => Bool, default => 0 ],
17             ],
18             Gathering => [
19 2         11 gather_as => [ is => 'ro', isa => ArrayRef[Str], default => sub { [] } ],
  0         0  
20             ],
21 2     2   924 );
  2         2041  
22              
23 2     2   276568 use Exporter::Tiny ();
  2         6  
  2         1054  
24             our @ISA = qw( Exporter::Tiny );
25             our @EXPORT_OK = qw( WithURI Gathering );
26             our %EXPORT_TAGS = (
27             traits => [qw( WithURI Gathering )]
28             );
29              
30             our %seen;
31              
32             sub _gather_objects
33             {
34 0     0     my ($self, $relation) = @_;
35 0 0         return if $seen{$self}++;
36            
37 0 0         if (ArrayRef->check($self))
38             {
39 0           return uniq(
40             grep defined, map _gather_objects($_, $relation), grep defined, @$self
41             );
42             }
43            
44 0 0         if (Object->check($self))
45             {
46 0 0         return unless $self->isa('Moose::Object');
47            
48 0 0 0       my @local =
49             grep defined,
50             map ArrayRef->check($_) ? @$_ : $_,
51             map $_->get_value($self),
52             grep $_->does(Gathering) && match($relation, $_->gather_as),
53             $self->meta->get_all_attributes;
54            
55 0   0       my @recursive =
56             grep defined,
57             map _gather_objects($_, $relation),
58             grep defined,
59             map $_->get_value($self),
60             grep !($_->does(Gathering) && match($relation, $_->gather_as)),
61             $self->meta->get_all_attributes;
62            
63 0           return uniq(@local, @recursive);
64             }
65             }
66              
67             sub gather_objects
68             {
69 0     0 0   local %seen;
70 0           grep ref, _gather_objects(@_);
71             }
72              
73             1;