File Coverage

blib/lib/Wikibase/Datatype/Print/MediainfoSnak.pm
Criterion Covered Total %
statement 33 34 97.0
branch 11 12 91.6
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 52 54 96.3


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Print::MediainfoSnak;
2              
3 9     9   936574 use base qw(Exporter);
  9         53  
  9         1158  
4 9     9   64 use strict;
  9         25  
  9         189  
5 9     9   60 use warnings;
  9         33  
  9         329  
6              
7 9     9   959 use Error::Pure qw(err);
  9         22736  
  9         345  
8 9     9   166 use Readonly;
  9         28  
  9         448  
9 9     9   1484 use Wikibase::Datatype::Print::Value;
  9         28  
  9         2514  
10              
11             Readonly::Array our @EXPORT_OK => qw(print);
12              
13             our $VERSION = 0.12;
14              
15             sub print {
16 8     8 1 8466 my ($obj, $opts_hr) = @_;
17              
18 8 100       48 if (! $obj->isa('Wikibase::Datatype::MediainfoSnak')) {
19 1         6 err "Object isn't 'Wikibase::Datatype::MediainfoSnak'.";
20             }
21              
22 7         16 my $property_name = '';
23 7 100       25 if (exists $opts_hr->{'cache'}) {
24 1         9 $property_name = $opts_hr->{'cache'}->get('label', $obj->property);
25 1 50       81 if (defined $property_name) {
26 1         4 $property_name = " ($property_name)";
27             } else {
28 0         0 $property_name = '';
29             }
30             }
31              
32 7         41 my $ret = $obj->property.$property_name.': ';
33 7 100       78 if ($obj->snaktype eq 'value') {
    100          
    100          
34 4         53 $ret .= Wikibase::Datatype::Print::Value::print($obj->datavalue, $opts_hr);
35             } elsif ($obj->snaktype eq 'novalue') {
36 1         15 $ret .= 'no value';
37             } elsif ($obj->snaktype eq 'somevalue') {
38 1         18 $ret .= 'unknown value';
39             } else {
40 1         18 err 'Bad snaktype.',
41             'snaktype', $obj->snaktype,
42             ;
43             }
44              
45 6         31 return $ret;
46             }
47              
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =encoding utf8
55              
56             =head1 NAME
57              
58             Wikibase::Datatype::Print::MediainfoSnak - Wikibase mediainfo snak pretty print helpers.
59              
60             =head1 SYNOPSIS
61              
62             use Wikibase::Datatype::Print::MediainfoSnak qw(print);
63              
64             my $pretty_print_string = print($obj, $opts_hr);
65              
66             =head1 SUBROUTINES
67              
68             =head2 C<print>
69              
70             my $pretty_print_string = print($obj, $opts_hr);
71              
72             Construct pretty print output for L<Wikibase::Datatype::MediainfoSnak>
73             object.
74              
75             Returns string.
76              
77             =head1 ERRORS
78              
79             print():
80             Object isn't 'Wikibase::Datatype::MediainfoSnak'.
81             Bad snaktype.
82             snaktype: %s
83              
84             =head1 EXAMPLE1
85              
86             =for comment filename=create_and_print_mediainfo_snak.pl
87              
88             use strict;
89             use warnings;
90              
91             use Wikibase::Datatype::Print::MediainfoSnak;
92             use Wikibase::Datatype::MediainfoSnak;
93             use Wikibase::Datatype::Value::Item;
94              
95             # Object.
96             my $obj = Wikibase::Datatype::MediainfoSnak->new(
97             'datavalue' => Wikibase::Datatype::Value::Item->new(
98             'value' => 'Q5',
99             ),
100             'property' => 'P31',
101             );
102              
103             # Print.
104             print Wikibase::Datatype::Print::MediainfoSnak::print($obj)."\n";
105              
106             # Output:
107             # P31: Q5
108              
109             =head1 EXAMPLE2
110              
111             =for comment filename=create_and_print_mediainfo_snak_translated.pl
112              
113             use strict;
114             use warnings;
115              
116             use Wikibase::Cache;
117             use Wikibase::Cache::Backend::Basic;
118             use Wikibase::Datatype::Print::MediainfoSnak;
119             use Wikibase::Datatype::MediainfoSnak;
120             use Wikibase::Datatype::Value::Item;
121              
122             # Object.
123             my $obj = Wikibase::Datatype::MediainfoSnak->new(
124             'datavalue' => Wikibase::Datatype::Value::Item->new(
125             'value' => 'Q5',
126             ),
127             'property' => 'P31',
128             );
129              
130             # Cache.
131             my $cache = Wikibase::Cache->new(
132             'backend' => 'Basic',
133             );
134              
135             # Print.
136             print Wikibase::Datatype::Print::MediainfoSnak::print($obj, {
137             'cache' => $cache,
138             })."\n";
139              
140             # Output:
141             # P31 (instance of): Q5
142              
143             =head1 DEPENDENCIES
144              
145             L<Error::Pure>,
146             L<Exporter>,
147             L<Readonly>,
148             L<Wikibase::Datatype::Print::Value>.
149              
150             =head1 SEE ALSO
151              
152             =over
153              
154             =item L<Wikibase::Datatype::MediainfoSnak>
155              
156             Wikibase mediainfo snak datatype.
157              
158             =back
159              
160             =head1 REPOSITORY
161              
162             L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print>
163              
164             =head1 AUTHOR
165              
166             Michal Josef Špaček L<mailto:skim@cpan.org>
167              
168             L<http://skim.cz>
169              
170             =head1 LICENSE AND COPYRIGHT
171              
172             © 2020-2023 Michal Josef Špaček
173              
174             BSD 2-Clause License
175              
176             =head1 VERSION
177              
178             0.12
179              
180             =cut
181