RDF/Generator/Void/Meta/Attribute/ObjectList.pm

filter: Statementstmt 100% 20 / 20 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 89.6% 26 / 29 CC 4 SCAR 11.1
CC
4
Cov
88%
__ANON__
4.1
BEGIN
1.0
__ANON__
1.0
CRAP 3.0
« App/perlrdf/Command/Void.pm ↑ Summary
1 package RDF::Generator::Void::Meta::Attribute::ObjectList;
2  
3 5 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5  
6 =head1 NAME
7  
8 RDF::Generator::Void::Meta::Attribute::ObjectList - Trait for list of RDF objects
9  
10 =head1 SYNOPSIS
11  
12 has _endpoints => ( traits => ['ObjectList'] );
13 has _titles => (
14 traits => ['ObjectList'],
15 isa => 'ArrayRef[RDF::Trine::Node::Literal]',
16 );
17 has resources => ( traits => ['ObjectList'] );
18  
19 =head2 DESCRIPTION
20  
21 This module gives you a trait to manage a list of RDF resources
22 typically used in an object position in an RDF triple. When declaring
23 attributes, you may use C<traits => ['ObjectList']> alone in which
24 case it'll give you a arrayref of strings and the methods to push to
25 the array, list all strings in the array, and to check if it is
26 empty. These are created by prefixing C<add_>, C<all_> and C<has_no_>
27 to your attribute name, respectively.
28  
29 If you have an underscore in the beginning, the attribute will not
30 itself be a method, but you can still use the non-prefixed attribute
31 name as argument to the constructor, and you will have the same methods as above.
32  
33 You may also give a C<isa> argument to the attribute. In that case,
34 you may set the arrayref to contain something other than strings, like
35 in the example above.
36  
37 =cut
38  
39 5 with (
40 'Moose::Meta::Attribute::Native::Trait::Array',
41 );
42  
43 20 ▶around _process_options => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
44 20 my $orig = shift;
45 20 my (undef, $attr_name, $options) = @_;
46
47 20 $options->{is} = 'rw';
48 20 ▶ $options->{isa} = 'ArrayRef[Str]' unless exists $options->{isa};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options->{"isa"} 0 20 20
49  
50 20 ▶ if ($attr_name =~ /^_(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_name =~ /^_(.+)/) 20 0 20
51 20 $attr_name = $1;
52 20 $options->{init_arg} = $attr_name;
53 }
54
55 # WTF isn't this like crazy to add traits to the class in a trait. Hmm, Nah, that's okay.
56 20 ▶ $options->{traits} = [] unless exists $options->{traits};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options->{"traits"} 0 20 20
57 20 push @{ $options->{traits} }, 'Moose::Meta::Attribute::Native::Trait::Array';
58
59 20 ▶ $options->{default} = sub {[]};
Subroutine __ANON__: called CC=1 SCAR=0.0
60 $options->{handles} = {
61 20 sprintf("add_%s", $attr_name) => 'push',
62 sprintf("all_%s", $attr_name) => 'uniq',
63 sprintf("has_no_%s", $attr_name) => 'is_empty',
64 };
65 20 $orig->(@_);
66 5 };
67  
68  
69  
70 =head1 FURTHER DOCUMENTATION
71  
72 Please see L<RDF::Generator::Void> for further documentation.
73  
74 =head1 AUTHORS AND COPYRIGHT
75  
76 This module was prototyped by Konstantin Baierer and is mostly his work.
77  
78 Please see L<RDF::Generator::Void> for more information about authors
79 and copyright for this module.
80  
81  
82 =cut
83  
84 5 1;
« App/perlrdf/Command/Void.pm ↑ Summary