File Coverage

blib/lib/CryptoExchange/Catalog.pm
Criterion Covered Total %
statement 39 45 86.6
branch 9 12 75.0
condition n/a
subroutine 9 11 81.8
pod 8 8 100.0
total 65 76 85.5


line stmt bran cond sub pod time code
1             package CryptoExchange::Catalog;
2              
3             our $DATE = '2018-05-10'; # DATE
4             our $VERSION = '20180510'; # VERSION
5              
6 1     1   75765 use 5.010001;
  1         15  
7 1     1   8 use strict;
  1         3  
  1         41  
8 1     1   7 use warnings;
  1         3  
  1         777  
9              
10             my %by_name_lc;
11             my %by_safename;
12             my %by_code_lc;
13             my @all_data;
14              
15             sub new {
16 1     1 1 113 my $class = shift;
17              
18 1 50       6 unless (keys %by_name_lc) {
19 1         7 while (defined(my $line = )) {
20 213         458 chomp $line;
21 213         768 my @ff = split /\t/, $line;
22 213         604 my ($name, $safename, $code) = @ff;
23 213         666 $by_name_lc{lc $name} = \@ff;
24 213         600 $by_safename{$safename} = \@ff;
25 213 100       683 $by_code_lc{lc $code} = \@ff if defined $code;
26 213         1000 push @all_data, \@ff;
27             }
28             }
29              
30 1         16 bless {}, $class;
31             }
32              
33             sub by_name {
34 3     3 1 1531 my ($self, $name) = @_;
35             die "Can't find cryptoexchange with name '$name'"
36 3 100       37 unless my $rec = $by_name_lc{lc $name};
37             return {
38 2         34 name=>$rec->[0],
39             safename=>$rec->[1],
40             code=>$rec->[2],
41             };
42             }
43              
44             sub by_safename {
45 3     3 1 4037 my ($self, $safename) = @_;
46 3         7 $safename = lc($safename);
47             die "Can't find cryptoexchange with safename '$safename'"
48 3 100       18 unless my $rec = $by_safename{$safename};
49             return {
50 2         14 name=>$rec->[0],
51             safename=>$rec->[1],
52             code=>$rec->[2],
53             };
54             }
55              
56             sub by_code {
57 3     3 1 1941 my ($self, $code) = @_;
58             die "Can't find cryptoexchange with code '$code'"
59 3 100       36 unless my $rec = $by_code_lc{lc $code};
60             return {
61 2         14 name=>$rec->[0],
62             safename=>$rec->[1],
63             code=>$rec->[2],
64             };
65             }
66              
67 0     0 1 0 sub by_slug { by_safename(@_) }
68              
69             sub all_names {
70 1     1 1 1807 my $self = shift;
71 1         2 my @res;
72 1         3 for (@all_data) {
73 213         297 push @res, $_->[0];
74             }
75 1         38 @res;
76             }
77              
78             sub all_codes {
79 0     0 1 0 my $self = shift;
80 0         0 my @res;
81 0         0 for (@all_data) {
82 0 0       0 push @res, $_->[2] if defined $_->[2];
83             }
84 0         0 @res;
85             }
86              
87             sub all_data {
88 1     1 1 1664 my $self = shift;
89 1         2 my @res;
90 1         2 for (@all_data) {
91 213         510 push @res, {name=>$_->[0], safename=>$_->[1], code=>$_->[2]};
92             }
93 1         16 @res;
94             }
95              
96             1;
97             # ABSTRACT: Catalog of cryptoexchanges
98              
99             =pod
100              
101             =encoding UTF-8
102              
103             =head1 NAME
104              
105             CryptoExchange::Catalog - Catalog of cryptoexchanges
106              
107             =head1 VERSION
108              
109             This document describes version 20180510 of CryptoExchange::Catalog (from Perl distribution CryptoExchange-Catalog), released on 2018-05-10.
110              
111             =head1 SYNOPSIS
112              
113             use CryptoExchange::Catalog;
114              
115             my $cat = CryptoExchange::Catalog->new;
116              
117             my $record = $cat->by_name("BX Thailand"); # note: case-insensitive. => {name=>"BX Thailand", safename=>"bx-thailand", code=>"BX"}
118             my $record = $cat->by_safename("bx-thailand");
119             my $record = $cat->by_slug("bx-thailand"); # alias for by_safename(), mixed case also works
120              
121             my @names = $cat->all_names(); # => ("Binance", "Bithumb", ...)
122              
123             my @data = $cat->all_data; # => ({name=>"Binance", safename=>"binance", code=>"BINANCE"}, {...}, ...)
124              
125             =head1 DESCRIPTION
126              
127             This class attempts to provide a list/catalog of cryptocurrency exchanges. The
128             main source for this catalog is the Cryptocurrency Market Capitalizations
129             website (L, or CMC for short).
130              
131             =head1 METHODS
132              
133             =head2 new
134              
135             =head2 by_name
136              
137             =head2 by_safename
138              
139             =head2 by_code
140              
141             =head2 by_slug
142              
143             Alias for L.
144              
145             =head2 all_names
146              
147             =head2 all_codes
148              
149             =head2 all_data
150              
151             =head1 HOMEPAGE
152              
153             Please visit the project's homepage at L.
154              
155             =head1 SOURCE
156              
157             Source repository is at L.
158              
159             =head1 BUGS
160              
161             Please report any bugs or feature requests on the bugtracker website L
162              
163             When submitting a bug or request, please include a test-file or a
164             patch to an existing test-file that illustrates the bug or desired
165             feature.
166              
167             =head1 SEE ALSO
168              
169             L
170              
171             =head1 AUTHOR
172              
173             perlancar
174              
175             =head1 COPYRIGHT AND LICENSE
176              
177             This software is copyright (c) 2018 by perlancar@cpan.org.
178              
179             This is free software; you can redistribute it and/or modify it under
180             the same terms as the Perl 5 programming language system itself.
181              
182             =cut
183              
184             __DATA__