OurWorldInData/Catalog.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 44 CC 3 SCAR 16.1
CC
3
Cov
0%
find
12.0
get_path
2.0
get_topics
2.0
CRAP 5.0
1 package WebService::OurWorldInData::Catalog;
2 # ABSTRACT: Provides a limited search of Our World in Data charts
3  
4 use Moo;
5 extends 'WebService::OurWorldInData';
6  
7 use Carp;
8 use JSON qw(decode_json);
9 use PerlX::Maybe qw( maybe provided );
10 use Types::Standard qw( Str Bool Enum ); # Int ArrayRef HashRef InstanceOf ConsumerOf
11  
12 has query => (
13 is => 'rw',
14 isa => Str,
15 );
16  
17 # list of all the known charts
18 # should make it a constant
19 my @data = <DATA>;
20 chomp @data;
21  
22 =head1 NAME
23  
24 WebService::OurWorldInData::Catalog
25  
26 =head1 SYNOPSIS
27  
28 my $catalog = WebService::OurWorldInData::Catalog->new;
29  
30 my $results = $chart->find( 'covid' ); # get charts for covid
31 my @topics = $chart->get_topics;
32  
33 =head1 DESCRIPTION
34  
35 Pretends to search Our World in Data for data charts like the python api C<find>.
36  
37 =head1 Methods
38  
39 =head2 find
40  
41 Returns an array ref of charts matching the argument to C<find>.
42 You can give it a string or a regex as in
43  
44 $results = $chart->find( qr/covid|death/ );
45  
46 An empty call to C<find> will return all the charts it knows about.
47  
48 $all_results = $chart->find;
49  
50 Our World in Data holds the data on 14,368 charts across 123 topics
51 as of July 2025. Because they haven't opened up their Catalog API yet,
52 I've had to scrape their web page for results. This means that the
53 C<find> method is not dynamic, up-to-date or anywhere near complete.
54  
55 There are currently 3659 charts known by this module,
56 so you've got a 1 in 4 chance of finding what you're looking for.
57  
58 =head2 get_topics
59  
60 This will return a list of topics that I've scraped so far.
61 There are only 29 of the 123 known as of July 2025, but it should
62 give you a start.
63  
64 =head1 SEE ALSO
65  
66 =over 4
67  
68 =item * L<HTTP::Tiny>
69  
70 =back
71  
72 =cut
73  
74 sub get_path {
75 my $self = shift;
76 return join '/', $self->base_url, 'data';
77 }
78  
79 sub find {
80 my ($self, $query) = @_;
81  
82 $query = qr// unless defined $query;
83 $query = qr/$query/ unless ref $query eq 'Regexp';
84 my @hits = grep { /$query/ } @data;
85 return \@hits;
86  
87 # if we ever get an api to the data endpoint
88 #return $self->get_response( $url, { q => $query } );
89 }
90  
91 sub get_topics {
92 return qw(
93 age-structure
94 agricultural-production
95 air-pollution
96 alcohol-consumption
97 animal-welfare
98 antibiotics
99 artificial-intelligence
100 biodiversity
101 books
102 burden-of-disease
103 cancer
104 cardiovascular-diseases
105 causes-of-death
106 child-labor
107 child-mortality
108 clean-water
109 clean-water-sanitation
110 climate-change
111 co2-and-greenhouse-gas-emissions
112 coronavirus
113 corruption
114 crop-yields
115 democracy
116 diarrheal-diseases
117 diet-compositions
118 economic-growth
119 economic-inequality
120 economic-inequality-by-gender
121 electricity-mix
122 employment-in-agriculture
123 energy
124 energy-access
125 energy-mix
126 environmental-impacts-of-food
127 eradication-of-diseases
128 famines
129 farm-size
130 female-labor-supply
131 fertility-rate
132 fertilizers
133 financing-education
134 financing-healthcare
135 fish-and-overfishing
136 food-prices
137 food-supply
138 foreign-aid
139 forests-and-deforestation
140 fossil-fuels
141 gender-ratio
142 global-education
143 government-spending
144 happiness-and-life-satisfaction
145 health-meta
146 hiv-aids
147 homelessness
148 homicides
149 human-development-index
150 human-height
151 human-rights
152 hunger-and-undernourishment
153 illicit-drug-use
154 indoor-air-pollution
155 influenza
156 internet
157 land-use
158 lead-pollution
159 lgbt-rights
160 life-expectancy
161 light-at-night
162 literacy
163 malaria
164 marriages-and-divorces
165 maternal-mortality
166 meat-production
167 mental-health
168 metals-minerals
169 micronutrient-deficiency
170 migration
171 military-personnel-spending
172 mpox
173 natural-disasters
174 neglected-tropical-diseases
175 nuclear-energy
176 nuclear-weapons
177 obesity
178 oil-spills
179 outdoor-air-pollution
180 ozone-layer
181 pandemics
182 pesticides
183 plastic-pollution
184 pneumonia
185 polio
186 population-growth
187 poverty
188 renewable-energy
189 research-and-development
190 sanitation
191 smallpox
192 smoking
193 social-connections-and-loneliness
194 space-exploration-satellites
195 state-capacity
196 suicide
197 taxation
198 technological-change
199 terrorism
200 tetanus
201 time-use
202 tourism
203 trade-and-globalization
204 transport
205 trust
206 tuberculosis
207 urbanization
208 vaccination
209 violence-against-rights-for-children
210 war-and-peace
211 waste-management
212 water-use-stress
213 wildfires
214 women-rights
215 working-hours
216 );
217 }
218  
219 1;
220  
221 __DATA__