File Coverage

blib/lib/Wikibase/Datatype/Print/Value/Property.pm
Criterion Covered Total %
statement 25 25 100.0
branch 6 6 100.0
condition 5 6 83.3
subroutine 6 6 100.0
pod 1 1 100.0
total 43 44 97.7


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Print::Value::Property;
2              
3 44     44   916917 use base qw(Exporter);
  44         124  
  44         3994  
4 44     44   324 use strict;
  44         109  
  44         889  
5 44     44   218 use warnings;
  44         100  
  44         1339  
6              
7 44     44   1177 use Error::Pure qw(err);
  44         23339  
  44         1891  
8 44     44   450 use Readonly;
  44         110  
  44         9766  
9              
10             Readonly::Array our @EXPORT_OK => qw(print);
11              
12             our $VERSION = 0.13;
13              
14             sub print {
15 6     6 1 7399 my ($obj, $opts_hr) = @_;
16              
17 6 100       36 if (! $obj->isa('Wikibase::Datatype::Value::Property')) {
18 1         5 err "Object isn't 'Wikibase::Datatype::Value::Property'.";
19             }
20              
21 5 100 100     39 if (exists $opts_hr->{'cb'} && ! $opts_hr->{'cb'}->isa('Wikibase::Cache')) {
22 1         6 err "Option 'cb' must be a instance of Wikibase::Cache.";
23             }
24              
25 4         9 my $property;
26 4 100       13 if (exists $opts_hr->{'cb'}) {
27 2   66     7 $property = $opts_hr->{'cb'}->get('label', $obj->value) || $obj->value;
28             } else {
29 2         72 $property = $obj->value;
30             }
31              
32 4         163 return $property;
33             }
34              
35             1;
36              
37             __END__
38              
39             =pod
40              
41             =encoding utf8
42              
43             =head1 NAME
44              
45             Wikibase::Datatype::Print::Value::Property - Wikibase property value pretty print helpers.
46              
47             =head1 SYNOPSIS
48              
49             use Wikibase::Datatype::Print::Value::Property qw(print);
50              
51             my $pretty_print_string = print($obj, $opts_hr);
52             my @pretty_print_lines = print($obj, $opts_hr);
53              
54             =head1 SUBROUTINES
55              
56             =head2 C<print>
57              
58             my $pretty_print_string = print($obj, $opts_hr);
59             my @pretty_print_lines = print($obj, $opts_hr);
60              
61             Construct pretty print output for L<Wikibase::Datatype::Value::Property>
62             object.
63              
64             Returns string in scalar context.
65             Returns list of lines in array context.
66              
67             =head1 ERRORS
68              
69             print():
70             Object isn't 'Wikibase::Datatype::Value::Property'.
71             Option 'cb' must be a instance of Wikibase::Cache.
72              
73             =head1 EXAMPLE
74              
75             =for comment filename=create_and_print_value_property.pl
76              
77             use strict;
78             use warnings;
79              
80             use Wikibase::Datatype::Print::Value::Property;
81             use Wikibase::Datatype::Value::Property;
82              
83             # Object.
84             my $obj = Wikibase::Datatype::Value::Property->new(
85             'value' => 'P31',
86             );
87              
88             # Print.
89             print Wikibase::Datatype::Print::Value::Property::print($obj)."\n";
90              
91             # Output:
92             # P31
93              
94             =head1 DEPENDENCIES
95              
96             L<Error::Pure>,
97             L<Exporter>,
98             L<Readonly>.
99              
100             =head1 SEE ALSO
101              
102             =over
103              
104             =item L<Wikibase::Datatype::Value::Property>
105              
106             Wikibase property value datatype.
107              
108             =back
109              
110             =head1 REPOSITORY
111              
112             L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print>
113              
114             =head1 AUTHOR
115              
116             Michal Josef Špaček L<mailto:skim@cpan.org>
117              
118             L<http://skim.cz>
119              
120             =head1 LICENSE AND COPYRIGHT
121              
122             © 2020-2023 Michal Josef Špaček
123              
124             BSD 2-Clause License
125              
126             =head1 VERSION
127              
128             0.13
129              
130             =cut