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-06-05'; # DATE
4             our $VERSION = '20180605.1.0'; # VERSION
5              
6 1     1   51866 use 5.010001;
  1         10  
7 1     1   4 use strict;
  1         2  
  1         23  
8 1     1   6 use warnings;
  1         1  
  1         441  
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 70 my $class = shift;
17              
18 1 50       5 unless (keys %by_name_lc) {
19 1         5 while (defined(my $line = )) {
20 210         213 chomp $line;
21 210         314 my @ff = split /\t/, $line;
22 210         271 my ($name, $safename, $code) = @ff;
23 210         365 $by_name_lc{lc $name} = \@ff;
24 210         271 $by_safename{$safename} = \@ff;
25 210 100       311 $by_code_lc{lc $code} = \@ff if defined $code;
26 210         415 push @all_data, \@ff;
27             }
28             }
29              
30 1         4 bless {}, $class;
31             }
32              
33             sub by_name {
34 3     3 1 986 my ($self, $name) = @_;
35             die "Can't find cryptoexchange with name '$name'"
36 3 100       31 unless my $rec = $by_name_lc{lc $name};
37             return {
38 2         18 name=>$rec->[0],
39             safename=>$rec->[1],
40             code=>$rec->[2],
41             };
42             }
43              
44             sub by_safename {
45 3     3 1 3407 my ($self, $safename) = @_;
46 3         6 $safename = lc($safename);
47             die "Can't find cryptoexchange with safename '$safename'"
48 3 100       17 unless my $rec = $by_safename{$safename};
49             return {
50 2         13 name=>$rec->[0],
51             safename=>$rec->[1],
52             code=>$rec->[2],
53             };
54             }
55              
56             sub by_code {
57 3     3 1 1735 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         12 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 1559 my $self = shift;
71 1         2 my @res;
72 1         3 for (@all_data) {
73 210         274 push @res, $_->[0];
74             }
75 1         34 @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 1599 my $self = shift;
89 1         2 my @res;
90 1         2 for (@all_data) {
91 210         439 push @res, {name=>$_->[0], safename=>$_->[1], code=>$_->[2]};
92             }
93 1         29 @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 20180605.1.0 of CryptoExchange::Catalog (from Perl distribution CryptoExchange-Catalog), released on 2018-06-05.
110              
111             =head1 SYNOPSIS
112              
113             use CryptoExchange::Catalog;
114              
115             my $cat = CryptoExchange::Catalog->new;
116              
117             my $record;
118             $record = $cat->by_name("BX Thailand"); # note: case-insensitive. => {name=>"BX Thailand", safename=>"bx-thailand", code=>"BX"}
119             $record = $cat->by_safename("bx-thailand");
120             $record = $cat->by_slug("bx-thailand"); # alias for by_safename(), mixed case also works
121             $record = $cat->by_code("BX"); # note: currently not all exchanges are assign (short) code
122              
123             my @names = $cat->all_names(); # => ("BX Thailand", "Binance", ...)
124              
125             my @codes = $cat->all_codes(); # => ("BX", "BINANCE", ...)
126              
127             my @data = $cat->all_data; # => ({name=>"BX Thailand", safename=>"bx-thailand", code=>"BX"}, {name=>"Binance", safename=>"binance", code=>"BINANCE"}, {...}, ...)
128              
129             =head1 DESCRIPTION
130              
131             This class attempts to provide a list/catalog of cryptocurrency exchanges. The
132             main source for this catalog is the Cryptocurrency Market Capitalizations
133             website (L, or CMC for short).
134              
135             =head1 METHODS
136              
137             =head2 new
138              
139             =head2 by_name
140              
141             =head2 by_safename
142              
143             =head2 by_code
144              
145             =head2 by_slug
146              
147             Alias for L.
148              
149             =head2 all_names
150              
151             =head2 all_codes
152              
153             =head2 all_data
154              
155             =head1 HOMEPAGE
156              
157             Please visit the project's homepage at L.
158              
159             =head1 SOURCE
160              
161             Source repository is at L.
162              
163             =head1 BUGS
164              
165             Please report any bugs or feature requests on the bugtracker website L
166              
167             When submitting a bug or request, please include a test-file or a
168             patch to an existing test-file that illustrates the bug or desired
169             feature.
170              
171             =head1 SEE ALSO
172              
173             L
174              
175             =head1 AUTHOR
176              
177             perlancar
178              
179             =head1 COPYRIGHT AND LICENSE
180              
181             This software is copyright (c) 2018 by perlancar@cpan.org.
182              
183             This is free software; you can redistribute it and/or modify it under
184             the same terms as the Perl 5 programming language system itself.
185              
186             =cut
187              
188             __DATA__