| 1 | package CryptoCurrency::Catalog; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | our $DATE = '2018-11-29'; # DATE | |||||||||
| 4 | 2 | our $VERSION = '20181129.0.0'; # VERSION | |||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | my %by_code; | |||||||||
| 11 | my %by_name_lc; | ||||||||||
| 12 | 2 | my %by_safename; | |||||||||
| 13 | 2 | my @all_data; | |||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 16 | 1 | my $class = shift; | |||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | unless (keys %by_code) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 1 | ▶ | while (defined(my $line = <DATA>)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 2076 | chomp $line; | |||||||||
| 21 | 2076 | my @ff = split /\t/, $line; | |||||||||
| 22 | 2076 | my ($code, $name, $safename) = @ff; | |||||||||
| 23 | 2076 | $by_code{$code} = \@ff; | |||||||||
| 24 | 2076 | $by_name_lc{lc $name} = \@ff; | |||||||||
| 25 | 2076 | $by_safename{$safename} = \@ff; | |||||||||
| 26 | 2076 | push @all_data, \@ff; | |||||||||
| 27 | } | ||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 1 | bless {}, $class; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 3 | ▶ | sub by_code { | ||||||||
|
Subroutine
by_code: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 34 | 3 | my ($self, $code) = @_; | |||||||||
| 35 | 3 | $code = uc($code); | |||||||||
| 36 | die "Can't find cryptocurrency with code '$code'" | ||||||||||
| 37 | 3 | ▶ | unless $by_code{$code}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | return { | ||||||||||
| 39 | code=>$code, | ||||||||||
| 40 | name=>$by_code{$code}[1], | ||||||||||
| 41 | 2 | safename=>$by_code{$code}[2], | |||||||||
| 42 | }; | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | sub by_ticker { by_code(@_) } | ||||||||
|
Subroutine
by_ticker: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | |||||||||||
| 47 | 3 | ▶ | sub by_name { | ||||||||
|
Subroutine
by_name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | 3 | my ($self, $name) = @_; | |||||||||
| 49 | die "Can't find cryptocurrency with name '$name'" | ||||||||||
| 50 | 3 | ▶ | unless my $rec = $by_name_lc{lc $name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | return { | ||||||||||
| 52 | 2 | name=>$rec->[1], | |||||||||
| 53 | code=>$rec->[0], | ||||||||||
| 54 | safename=>$rec->[2], | ||||||||||
| 55 | }; | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 3 | ▶ | sub by_safename { | ||||||||
|
Subroutine
by_safename: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 59 | 3 | my ($self, $safename) = @_; | |||||||||
| 60 | 3 | $safename = lc($safename); | |||||||||
| 61 | die "Can't find cryptocurrency with safename '$safename'" | ||||||||||
| 62 | 3 | ▶ | unless $by_safename{$safename}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | return { | ||||||||||
| 64 | safename=>$safename, | ||||||||||
| 65 | code=>$by_safename{$safename}[0], | ||||||||||
| 66 | 2 | name=>$by_safename{$safename}[1], | |||||||||
| 67 | }; | ||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 1 | ▶ | sub by_slug { by_safename(@_) } | ||||||||
|
Subroutine
by_slug: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 71 | |||||||||||
| 72 | 1 | ▶ | sub all_codes { | ||||||||
|
Subroutine
all_codes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 73 | 1 | my $self = shift; | |||||||||
| 74 | 1 | my @res; | |||||||||
| 75 | 1 | for (@all_data) { | |||||||||
| 76 | 2076 | push @res, $_->[0]; | |||||||||
| 77 | } | ||||||||||
| 78 | 1 | @res; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 1 | ▶ | sub all_data { | ||||||||
|
Subroutine
all_data: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 82 | 1 | my $self = shift; | |||||||||
| 83 | 1 | my @res; | |||||||||
| 84 | 1 | for (@all_data) { | |||||||||
| 85 | 2076 | push @res, {code=>$_->[0], name=>$_->[1], safename=>$_->[2]}; | |||||||||
| 86 | } | ||||||||||
| 87 | 1 | @res; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 2 | 1; | |||||||||
| 91 | # ABSTRACT: Catalog of cryptocurrencies | ||||||||||
| 92 | |||||||||||
| 93 | =pod | ||||||||||
| 94 | |||||||||||
| 95 | =encoding UTF-8 | ||||||||||
| 96 | |||||||||||
| 97 | =head1 NAME | ||||||||||
| 98 | |||||||||||
| 99 | CryptoCurrency::Catalog - Catalog of cryptocurrencies | ||||||||||
| 100 | |||||||||||
| 101 | =head1 VERSION | ||||||||||
| 102 | |||||||||||
| 103 | This document describes version 20181129.0.0 of CryptoCurrency::Catalog (from Perl distribution CryptoCurrency-Catalog), released on 2018-11-29. | ||||||||||
| 104 | |||||||||||
| 105 | =head1 SYNOPSIS | ||||||||||
| 106 | |||||||||||
| 107 | use CryptoCurrency::Catalog; | ||||||||||
| 108 | |||||||||||
| 109 | my $cat = CryptoCurrency::Catalog->new; | ||||||||||
| 110 | |||||||||||
| 111 | my $record = $cat->by_code("ETH"); # => { code=>"ETH", name=>"Ethereum", safename=>"ethereum" } | ||||||||||
| 112 | my $record = $cat->by_ticker("eth"); # alias for by_code(), lowercase also works | ||||||||||
| 113 | my $record = $cat->by_name("Ethereum"); # note: case-sensitive | ||||||||||
| 114 | my $record = $cat->by_safename("ethereum"); | ||||||||||
| 115 | my $record = $cat->by_slug("Ethereum"); # alias for by_safename(), mixed case also works | ||||||||||
| 116 | |||||||||||
| 117 | my @codes = $cat->all_codes(); # => ("BTC", "ETH", ...) | ||||||||||
| 118 | |||||||||||
| 119 | my @data = $cat->all_data; # => ({code=>"BTC", name=>"Bitcoin", safename=>"bitcoin"}, {...}, ...) | ||||||||||
| 120 | |||||||||||
| 121 | =head1 DESCRIPTION | ||||||||||
| 122 | |||||||||||
| 123 | This class attempts to provide a list/catalog of cryptocurrencies. The main | ||||||||||
| 124 | source for this catalog is the Cryptocurrency Market Capitalizations website | ||||||||||
| 125 | (L<https://coinmarketcap.com/>, or CMC for short). | ||||||||||
| 126 | |||||||||||
| 127 | CMC does not provide unique codes nor unique names, only unique "safenames" | ||||||||||
| 128 | (slugs). Whenever there is a clash, this catalog modifies the clashing code | ||||||||||
| 129 | and/or unique name to make code and name to be unique again (usually the | ||||||||||
| 130 | coin/token with the smaller market cap "loses" the name). | ||||||||||
| 131 | |||||||||||
| 132 | There is no guarantee that the code/name/safename of old/unlisted coins or | ||||||||||
| 133 | tokens will not be reused. | ||||||||||
| 134 | |||||||||||
| 135 | =head1 METHODS | ||||||||||
| 136 | |||||||||||
| 137 | =head2 new | ||||||||||
| 138 | |||||||||||
| 139 | =head2 by_code | ||||||||||
| 140 | |||||||||||
| 141 | =head2 by_ticker | ||||||||||
| 142 | |||||||||||
| 143 | Alias for L</"by_code">. | ||||||||||
| 144 | |||||||||||
| 145 | =head2 by_name | ||||||||||
| 146 | |||||||||||
| 147 | =head2 by_safename | ||||||||||
| 148 | |||||||||||
| 149 | =head2 by_slug | ||||||||||
| 150 | |||||||||||
| 151 | Alias for L</"by_safename">. | ||||||||||
| 152 | |||||||||||
| 153 | =head2 all_codes | ||||||||||
| 154 | |||||||||||
| 155 | =head2 all_data | ||||||||||
| 156 | |||||||||||
| 157 | =head1 HOMEPAGE | ||||||||||
| 158 | |||||||||||
| 159 | Please visit the project's homepage at L<https://metacpan.org/release/CryptoCurrency-Catalog>. | ||||||||||
| 160 | |||||||||||
| 161 | =head1 SOURCE | ||||||||||
| 162 | |||||||||||
| 163 | Source repository is at L<https://github.com/perlancar/perl-CryptoCurrency-Catalog>. | ||||||||||
| 164 | |||||||||||
| 165 | =head1 BUGS | ||||||||||
| 166 | |||||||||||
| 167 | Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=CryptoCurrency-Catalog> | ||||||||||
| 168 | |||||||||||
| 169 | When submitting a bug or request, please include a test-file or a | ||||||||||
| 170 | patch to an existing test-file that illustrates the bug or desired | ||||||||||
| 171 | feature. | ||||||||||
| 172 | |||||||||||
| 173 | =head1 SEE ALSO | ||||||||||
| 174 | |||||||||||
| 175 | L<CryptoExchange::Catalog> | ||||||||||
| 176 | |||||||||||
| 177 | =head1 AUTHOR | ||||||||||
| 178 | |||||||||||
| 179 | perlancar <perlancar@cpan.org> | ||||||||||
| 180 | |||||||||||
| 181 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 182 | |||||||||||
| 183 | This software is copyright (c) 2018 by perlancar@cpan.org. | ||||||||||
| 184 | |||||||||||
| 185 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 186 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 187 | |||||||||||
| 188 | =cut | ||||||||||
| 189 | |||||||||||
| 190 | __DATA__ | ||||||||||