File Coverage

blib/lib/Wikibase/Datatype/Print/Value.pm
Criterion Covered Total %
statement 55 55 100.0
branch 18 18 100.0
condition n/a
subroutine 14 14 100.0
pod 1 1 100.0
total 88 88 100.0


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Print::Value;
2              
3 41     41   923336 use base qw(Exporter);
  41         229  
  41         3777  
4 41     41   271 use strict;
  41         86  
  41         806  
5 41     41   214 use warnings;
  41         120  
  41         1318  
6              
7 41     41   1171 use Error::Pure qw(err);
  41         23161  
  41         1691  
8 41     41   383 use Readonly;
  41         111  
  41         1692  
9 41     41   17949 use Wikibase::Datatype::Print::Value::Globecoordinate;
  41         122  
  41         1703  
10 41     41   16114 use Wikibase::Datatype::Print::Value::Item;
  41         125  
  41         1657  
11 41     41   17921 use Wikibase::Datatype::Print::Value::Monolingual;
  41         129  
  41         1711  
12 41     41   17013 use Wikibase::Datatype::Print::Value::Property;
  41         134  
  41         1691  
13 41     41   17321 use Wikibase::Datatype::Print::Value::Quantity;
  41         109  
  41         1650  
14 41     41   17006 use Wikibase::Datatype::Print::Value::Sense;
  41         139  
  41         1705  
15 41     41   17331 use Wikibase::Datatype::Print::Value::String;
  41         116  
  41         1817  
16 41     41   17618 use Wikibase::Datatype::Print::Value::Time;
  41         149  
  41         12365  
17              
18             Readonly::Array our @EXPORT_OK => qw(print);
19              
20             our $VERSION = 0.13;
21              
22             sub print {
23 45     45 1 15127 my ($obj, $opts_hr) = @_;
24              
25 45 100       217 if (! $obj->isa('Wikibase::Datatype::Value')) {
26 1         5 err "Object isn't 'Wikibase::Datatype::Value'.";
27             }
28              
29 44         242 my $type = $obj->type;
30 44         203 my $ret;
31 44 100       321 if ($type eq 'globecoordinate') {
    100          
    100          
    100          
    100          
    100          
    100          
    100          
32 1         6 $ret = Wikibase::Datatype::Print::Value::Globecoordinate::print($obj, $opts_hr);
33             } elsif ($type eq 'item') {
34 17         72 $ret = Wikibase::Datatype::Print::Value::Item::print($obj, $opts_hr);
35             } elsif ($type eq 'monolingualtext') {
36 1         6 $ret = Wikibase::Datatype::Print::Value::Monolingual::print($obj, $opts_hr);
37             } elsif ($type eq 'property') {
38 1         5 $ret = Wikibase::Datatype::Print::Value::Property::print($obj, $opts_hr);
39             } elsif ($type eq 'quantity') {
40 1         7 $ret = Wikibase::Datatype::Print::Value::Quantity::print($obj, $opts_hr);
41             } elsif ($type eq 'sense') {
42 1         7 $ret = Wikibase::Datatype::Print::Value::Sense::print($obj, $opts_hr);
43             } elsif ($type eq 'string') {
44 17         98 $ret = Wikibase::Datatype::Print::Value::String::print($obj, $opts_hr);
45             } elsif ($type eq 'time') {
46 4         20 $ret = Wikibase::Datatype::Print::Value::Time::print($obj, $opts_hr);
47             } else {
48 1         7 err "Type '$type' is unsupported.";
49             }
50              
51 43         293 return $ret;
52             }
53              
54             1;
55              
56             __END__
57              
58             =pod
59              
60             =encoding utf8
61              
62             =head1 NAME
63              
64             Wikibase::Datatype::Print::Value - Wikibase value pretty print helpers.
65              
66             =head1 SYNOPSIS
67              
68             use Wikibase::Datatype::Print::Value qw(print);
69              
70             my $pretty_print_string = print($obj, $opts_hr);
71             my @pretty_print_lines = print($obj, $opts_hr);
72              
73             =head1 SUBROUTINES
74              
75             =head2 C<print>
76              
77             my $pretty_print_string = print($obj, $opts_hr);
78             my @pretty_print_lines = print($obj, $opts_hr);
79              
80             Construct pretty print output for L<Wikibase::Datatype::Value>
81             object.
82              
83             Returns string in scalar context.
84             Returns list of lines in array context.
85              
86             =head1 ERRORS
87              
88             print():
89             Object isn't 'Wikibase::Datatype::Value'.
90             Type '%s' is unsupported.
91              
92             =head1 EXAMPLE
93              
94             =for comment filename=create_and_print_value.pl
95              
96             use strict;
97             use warnings;
98              
99             use Wikibase::Datatype::Print::Value;
100             use Wikibase::Datatype::Value::Item;
101              
102             # Object.
103             my $obj = Wikibase::Datatype::Value::Item->new(
104             'value' => 'Q123',
105             );
106              
107             # Print.
108             print Wikibase::Datatype::Print::Value::print($obj)."\n";
109              
110             # Output:
111             # Q123
112              
113             =head1 DEPENDENCIES
114              
115             L<Error::Pure>,
116             L<Exporter>,
117             L<Readonly>,
118             L<Wikibase::Datatype::Print::Value::Globecoordinate>,
119             L<Wikibase::Datatype::Print::Value::Item>,
120             L<Wikibase::Datatype::Print::Value::Monolingual>,
121             L<Wikibase::Datatype::Print::Value::Property>,
122             L<Wikibase::Datatype::Print::Value::Quantity>,
123             L<Wikibase::Datatype::Print::Value::Sense>,
124             L<Wikibase::Datatype::Print::Value::String>,
125             L<Wikibase::Datatype::Print::Value::Time>.
126              
127             =head1 SEE ALSO
128              
129             =over
130              
131             =item L<Wikibase::Datatype::Value>
132              
133             Wikibase value datatype.
134              
135             =back
136              
137             =head1 REPOSITORY
138              
139             L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print>
140              
141             =head1 AUTHOR
142              
143             Michal Josef Špaček L<mailto:skim@cpan.org>
144              
145             L<http://skim.cz>
146              
147             =head1 LICENSE AND COPYRIGHT
148              
149             © 2020-2023 Michal Josef Špaček
150              
151             BSD 2-Clause License
152              
153             =head1 VERSION
154              
155             0.13
156              
157             =cut