File Coverage

blib/lib/Wikibase/Datatype/Print/Value.pm
Criterion Covered Total %
statement 51 51 100.0
branch 16 16 100.0
condition n/a
subroutine 13 13 100.0
pod 1 1 100.0
total 81 81 100.0


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Print::Value;
2              
3 41     41   920349 use base qw(Exporter);
  41         217  
  41         3843  
4 41     41   284 use strict;
  41         101  
  41         820  
5 41     41   193 use warnings;
  41         100  
  41         1285  
6              
7 41     41   1187 use Error::Pure qw(err);
  41         23644  
  41         1574  
8 41     41   393 use Readonly;
  41         140  
  41         1923  
9 41     41   19096 use Wikibase::Datatype::Print::Value::Globecoordinate;
  41         132  
  41         1626  
10 41     41   16526 use Wikibase::Datatype::Print::Value::Item;
  41         142  
  41         1600  
11 41     41   17662 use Wikibase::Datatype::Print::Value::Monolingual;
  41         133  
  41         1650  
12 41     41   17633 use Wikibase::Datatype::Print::Value::Property;
  41         154  
  41         1636  
13 41     41   17765 use Wikibase::Datatype::Print::Value::Quantity;
  41         105  
  41         1726  
14 41     41   17265 use Wikibase::Datatype::Print::Value::String;
  41         109  
  41         1644  
15 41     41   17820 use Wikibase::Datatype::Print::Value::Time;
  41         161  
  41         11789  
16              
17             Readonly::Array our @EXPORT_OK => qw(print);
18              
19             our $VERSION = 0.09;
20              
21             sub print {
22 44     44 1 15404 my ($obj, $opts_hr) = @_;
23              
24 44 100       213 if (! $obj->isa('Wikibase::Datatype::Value')) {
25 1         7 err "Object isn't 'Wikibase::Datatype::Value'.";
26             }
27              
28 43         205 my $type = $obj->type;
29 43         206 my $ret;
30 43 100       328 if ($type eq 'globecoordinate') {
    100          
    100          
    100          
    100          
    100          
    100          
31 1         5 $ret = Wikibase::Datatype::Print::Value::Globecoordinate::print($obj, $opts_hr);
32             } elsif ($type eq 'item') {
33 17         81 $ret = Wikibase::Datatype::Print::Value::Item::print($obj, $opts_hr);
34             } elsif ($type eq 'monolingualtext') {
35 1         5 $ret = Wikibase::Datatype::Print::Value::Monolingual::print($obj, $opts_hr);
36             } elsif ($type eq 'property') {
37 1         14 $ret = Wikibase::Datatype::Print::Value::Property::print($obj, $opts_hr);
38             } elsif ($type eq 'quantity') {
39 1         4 $ret = Wikibase::Datatype::Print::Value::Quantity::print($obj, $opts_hr);
40             } elsif ($type eq 'string') {
41 17         87 $ret = Wikibase::Datatype::Print::Value::String::print($obj, $opts_hr);
42             } elsif ($type eq 'time') {
43 4         23 $ret = Wikibase::Datatype::Print::Value::Time::print($obj, $opts_hr);
44             } else {
45 1         5 err "Type '$type' is unsupported.";
46             }
47              
48 42         279 return $ret;
49             }
50              
51             1;
52              
53             __END__
54              
55             =pod
56              
57             =encoding utf8
58              
59             =head1 NAME
60              
61             Wikibase::Datatype::Print::Value - Wikibase value pretty print helpers.
62              
63             =head1 SYNOPSIS
64              
65             use Wikibase::Datatype::Print::Value qw(print);
66              
67             my $pretty_print_string = print($obj, $opts_hr);
68              
69             =head1 SUBROUTINES
70              
71             =head2 C<print>
72              
73             my $pretty_print_string = print($obj, $opts_hr);
74              
75             Construct pretty print output for L<Wikibase::Datatype::Value>
76             object.
77              
78             Returns string.
79              
80             =head1 ERRORS
81              
82             print():
83             Object isn't 'Wikibase::Datatype::Value'.
84             Type '%s' is unsupported.
85              
86             =head1 EXAMPLE
87              
88             =for comment filename=create_and_print_value.pl
89              
90             use strict;
91             use warnings;
92              
93             use Wikibase::Datatype::Print::Value;
94             use Wikibase::Datatype::Value::Item;
95              
96             # Object.
97             my $obj = Wikibase::Datatype::Value::Item->new(
98             'value' => 'Q123',
99             );
100              
101             # Print.
102             print Wikibase::Datatype::Print::Value::print($obj)."\n";
103              
104             # Output:
105             # Q123
106              
107             =head1 DEPENDENCIES
108              
109             L<Error::Pure>,
110             L<Exporter>,
111             L<Readonly>,
112             L<Wikibase::Datatype::Print::Value::Globecoordinate>,
113             L<Wikibase::Datatype::Print::Value::Item>,
114             L<Wikibase::Datatype::Print::Value::Monolingual>,
115             L<Wikibase::Datatype::Print::Value::Property>,
116             L<Wikibase::Datatype::Print::Value::Quantity>,
117             L<Wikibase::Datatype::Print::Value::String>,
118             L<Wikibase::Datatype::Print::Value::Time>.
119              
120             =head1 SEE ALSO
121              
122             =over
123              
124             =item L<Wikibase::Datatype::Value>
125              
126             Wikibase value datatype.
127              
128             =back
129              
130             =head1 REPOSITORY
131              
132             L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print>
133              
134             =head1 AUTHOR
135              
136             Michal Josef Špaček L<mailto:skim@cpan.org>
137              
138             L<http://skim.cz>
139              
140             =head1 LICENSE AND COPYRIGHT
141              
142             © 2020-2023 Michal Josef Špaček
143              
144             BSD 2-Clause License
145              
146             =head1 VERSION
147              
148             0.09
149              
150             =cut