├── .gitignore ├── .perltidyrc ├── .tidyallrc ├── LICENSE ├── README.md ├── bin └── carton ├── cpanfile ├── git ├── hooks │ └── pre-commit └── setup.sh ├── lib └── MetaCPAN │ └── Util.pm └── scripts ├── author ├── 1-fetch-single-author-curl.sh ├── 1-fetch-single-author-es.pl ├── 1-fetch-single-author-www-mech-cached.pl ├── 1-fetch-single-author.pl ├── 1a-search-authors.pl ├── 1b-scroll-all-authors-es.pl ├── 1c-scroll-all-authors-with-twitter-es.pl ├── 2-twitter-or-github-es.pl └── twitter.pl ├── distribution ├── 1-bugs-for-dist-es.pl └── 2-dists-with-rt-source.pl ├── favorite ├── 1-last-50-favorited-dists-es.pl ├── 1a-last-100-favorited-dists-by-user-es.pl ├── 2-favorites-previous-month-es.pl ├── 3-leaderboard-es.pl ├── 4-leaderboard-previous-month-es.pl ├── 5-plus-plus-your-favorites-es.pl └── 6-list-plussers-by-module.pl ├── file ├── 1-get-files-in-dist-es.pl ├── 2-get-dists-with-cpanfile.pl ├── 3-find-files-in-top-level-by-name.pl ├── 4-main-search.pl └── 5-size-of-cpan.pl ├── module ├── 1-fetch-single-module-es.pl └── 3-fetch-modules-in-release.pl ├── permission └── aggregate-author-perms.pl ├── pod ├── 1-fetch-single-pod-doc-as-html.pl ├── 1a-fetch-single-pod-doc-as-plain-text.pl └── README ├── release ├── 1-pkg2url-es.pl ├── 10-all-latest-releases.pl ├── 11-all-latest-releases-by-NEILB.pl ├── 12-all-latest-releases-by-NEILB-with-git-repository.pl ├── 13-all-releases-in-last-24-hours.pl ├── 1a-module2url-es.pl ├── 2-author-upload-leaderboard-es.pl ├── 3-author-uploads-one-author-es.pl ├── 4-latest-release-versions-es.pl ├── 4a-latest-release-versions-bool-filter-es.pl ├── 5-latest-releases-by-author-es.pl ├── 6-latest-releases-with-git-repo-es.pl ├── 7-all-releases-es.pl ├── 7-all-releases.pl ├── 8-all-releases-by-author-es.pl └── 9-all-releases-excluding-backpan.pl ├── reverse_dependencies ├── by-dist-www-mech.pl └── by-module-www-mech.pl └── search └── autocomplete └── www-mech.pl /.gitignore: -------------------------------------------------------------------------------- 1 | 02packages.details.txt 2 | .carton 3 | cpanfile.snapshot 4 | local 5 | *.swp 6 | .tidyall.d/ 7 | -------------------------------------------------------------------------------- /.perltidyrc: -------------------------------------------------------------------------------- 1 | -pbp 2 | -nst 3 | 4 | # Break a line after opening/before closing token. 5 | -vt=0 6 | -vtc=0 7 | -------------------------------------------------------------------------------- /.tidyallrc: -------------------------------------------------------------------------------- 1 | [PerlTidy] 2 | select = {bin,lib,scripts,t}/**/*.{pl,pm,t,psgi} 3 | select = app.psgi 4 | argv = --profile=$ROOT/.perltidyrc 5 | 6 | [SortLines] 7 | select = .gitignore 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This software is copyright (c) 2010 by Olaf Alders. 2 | 3 | This is free software; you can redistribute it and/or modify it under 4 | the same terms as the Perl 5 programming language system itself. 5 | 6 | Terms of the Perl programming language system itself 7 | 8 | a) the GNU General Public License as published by the Free 9 | Software Foundation; either version 1, or (at your option) any 10 | later version, or 11 | b) the "Artistic License" 12 | 13 | --- The GNU General Public License, Version 1, February 1989 --- 14 | 15 | This software is Copyright (c) 2010 by Olaf Alders. 16 | 17 | This is free software, licensed under: 18 | 19 | The GNU General Public License, Version 1, February 1989 20 | 21 | GNU GENERAL PUBLIC LICENSE 22 | Version 1, February 1989 23 | 24 | Copyright (C) 1989 Free Software Foundation, Inc. 25 | 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA 26 | 27 | Everyone is permitted to copy and distribute verbatim copies 28 | of this license document, but changing it is not allowed. 29 | 30 | Preamble 31 | 32 | The license agreements of most software companies try to keep users 33 | at the mercy of those companies. By contrast, our General Public 34 | License is intended to guarantee your freedom to share and change free 35 | software--to make sure the software is free for all its users. The 36 | General Public License applies to the Free Software Foundation's 37 | software and to any other program whose authors commit to using it. 38 | You can use it for your programs, too. 39 | 40 | When we speak of free software, we are referring to freedom, not 41 | price. Specifically, the General Public License is designed to make 42 | sure that you have the freedom to give away or sell copies of free 43 | software, that you receive source code or can get it if you want it, 44 | that you can change the software or use pieces of it in new free 45 | programs; and that you know you can do these things. 46 | 47 | To protect your rights, we need to make restrictions that forbid 48 | anyone to deny you these rights or to ask you to surrender the rights. 49 | These restrictions translate to certain responsibilities for you if you 50 | distribute copies of the software, or if you modify it. 51 | 52 | For example, if you distribute copies of a such a program, whether 53 | gratis or for a fee, you must give the recipients all the rights that 54 | you have. You must make sure that they, too, receive or can get the 55 | source code. And you must tell them their rights. 56 | 57 | We protect your rights with two steps: (1) copyright the software, and 58 | (2) offer you this license which gives you legal permission to copy, 59 | distribute and/or modify the software. 60 | 61 | Also, for each author's protection and ours, we want to make certain 62 | that everyone understands that there is no warranty for this free 63 | software. If the software is modified by someone else and passed on, we 64 | want its recipients to know that what they have is not the original, so 65 | that any problems introduced by others will not reflect on the original 66 | authors' reputations. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | GNU GENERAL PUBLIC LICENSE 72 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 73 | 74 | 0. This License Agreement applies to any program or other work which 75 | contains a notice placed by the copyright holder saying it may be 76 | distributed under the terms of this General Public License. The 77 | "Program", below, refers to any such program or work, and a "work based 78 | on the Program" means either the Program or any work containing the 79 | Program or a portion of it, either verbatim or with modifications. Each 80 | licensee is addressed as "you". 81 | 82 | 1. You may copy and distribute verbatim copies of the Program's source 83 | code as you receive it, in any medium, provided that you conspicuously and 84 | appropriately publish on each copy an appropriate copyright notice and 85 | disclaimer of warranty; keep intact all the notices that refer to this 86 | General Public License and to the absence of any warranty; and give any 87 | other recipients of the Program a copy of this General Public License 88 | along with the Program. You may charge a fee for the physical act of 89 | transferring a copy. 90 | 91 | 2. You may modify your copy or copies of the Program or any portion of 92 | it, and copy and distribute such modifications under the terms of Paragraph 93 | 1 above, provided that you also do the following: 94 | 95 | a) cause the modified files to carry prominent notices stating that 96 | you changed the files and the date of any change; and 97 | 98 | b) cause the whole of any work that you distribute or publish, that 99 | in whole or in part contains the Program or any part thereof, either 100 | with or without modifications, to be licensed at no charge to all 101 | third parties under the terms of this General Public License (except 102 | that you may choose to grant warranty protection to some or all 103 | third parties, at your option). 104 | 105 | c) If the modified program normally reads commands interactively when 106 | run, you must cause it, when started running for such interactive use 107 | in the simplest and most usual way, to print or display an 108 | announcement including an appropriate copyright notice and a notice 109 | that there is no warranty (or else, saying that you provide a 110 | warranty) and that users may redistribute the program under these 111 | conditions, and telling the user how to view a copy of this General 112 | Public License. 113 | 114 | d) You may charge a fee for the physical act of transferring a 115 | copy, and you may at your option offer warranty protection in 116 | exchange for a fee. 117 | 118 | Mere aggregation of another independent work with the Program (or its 119 | derivative) on a volume of a storage or distribution medium does not bring 120 | the other work under the scope of these terms. 121 | 122 | 3. You may copy and distribute the Program (or a portion or derivative of 123 | it, under Paragraph 2) in object code or executable form under the terms of 124 | Paragraphs 1 and 2 above provided that you also do one of the following: 125 | 126 | a) accompany it with the complete corresponding machine-readable 127 | source code, which must be distributed under the terms of 128 | Paragraphs 1 and 2 above; or, 129 | 130 | b) accompany it with a written offer, valid for at least three 131 | years, to give any third party free (except for a nominal charge 132 | for the cost of distribution) a complete machine-readable copy of the 133 | corresponding source code, to be distributed under the terms of 134 | Paragraphs 1 and 2 above; or, 135 | 136 | c) accompany it with the information you received as to where the 137 | corresponding source code may be obtained. (This alternative is 138 | allowed only for noncommercial distribution and only if you 139 | received the program in object code or executable form alone.) 140 | 141 | Source code for a work means the preferred form of the work for making 142 | modifications to it. For an executable file, complete source code means 143 | all the source code for all modules it contains; but, as a special 144 | exception, it need not include source code for modules which are standard 145 | libraries that accompany the operating system on which the executable 146 | file runs, or for standard header files or definitions files that 147 | accompany that operating system. 148 | 149 | 4. You may not copy, modify, sublicense, distribute or transfer the 150 | Program except as expressly provided under this General Public License. 151 | Any attempt otherwise to copy, modify, sublicense, distribute or transfer 152 | the Program is void, and will automatically terminate your rights to use 153 | the Program under this License. However, parties who have received 154 | copies, or rights to use copies, from you under this General Public 155 | License will not have their licenses terminated so long as such parties 156 | remain in full compliance. 157 | 158 | 5. By copying, distributing or modifying the Program (or any work based 159 | on the Program) you indicate your acceptance of this license to do so, 160 | and all its terms and conditions. 161 | 162 | 6. Each time you redistribute the Program (or any work based on the 163 | Program), the recipient automatically receives a license from the original 164 | licensor to copy, distribute or modify the Program subject to these 165 | terms and conditions. You may not impose any further restrictions on the 166 | recipients' exercise of the rights granted herein. 167 | 168 | 7. The Free Software Foundation may publish revised and/or new versions 169 | of the General Public License from time to time. Such new versions will 170 | be similar in spirit to the present version, but may differ in detail to 171 | address new problems or concerns. 172 | 173 | Each version is given a distinguishing version number. If the Program 174 | specifies a version number of the license which applies to it and "any 175 | later version", you have the option of following the terms and conditions 176 | either of that version or of any later version published by the Free 177 | Software Foundation. If the Program does not specify a version number of 178 | the license, you may choose any version ever published by the Free Software 179 | Foundation. 180 | 181 | 8. If you wish to incorporate parts of the Program into other free 182 | programs whose distribution conditions are different, write to the author 183 | to ask for permission. For software which is copyrighted by the Free 184 | Software Foundation, write to the Free Software Foundation; we sometimes 185 | make exceptions for this. Our decision will be guided by the two goals 186 | of preserving the free status of all derivatives of our free software and 187 | of promoting the sharing and reuse of software generally. 188 | 189 | NO WARRANTY 190 | 191 | 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 192 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 193 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 194 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 195 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 196 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 197 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 198 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 199 | REPAIR OR CORRECTION. 200 | 201 | 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 202 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 203 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 204 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 205 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 206 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 207 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 208 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 209 | POSSIBILITY OF SUCH DAMAGES. 210 | 211 | END OF TERMS AND CONDITIONS 212 | 213 | Appendix: How to Apply These Terms to Your New Programs 214 | 215 | If you develop a new program, and you want it to be of the greatest 216 | possible use to humanity, the best way to achieve this is to make it 217 | free software which everyone can redistribute and change under these 218 | terms. 219 | 220 | To do so, attach the following notices to the program. It is safest to 221 | attach them to the start of each source file to most effectively convey 222 | the exclusion of warranty; and each file should have at least the 223 | "copyright" line and a pointer to where the full notice is found. 224 | 225 | 226 | Copyright (C) 19yy 227 | 228 | This program is free software; you can redistribute it and/or modify 229 | it under the terms of the GNU General Public License as published by 230 | the Free Software Foundation; either version 1, or (at your option) 231 | any later version. 232 | 233 | This program is distributed in the hope that it will be useful, 234 | but WITHOUT ANY WARRANTY; without even the implied warranty of 235 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 236 | GNU General Public License for more details. 237 | 238 | You should have received a copy of the GNU General Public License 239 | along with this program; if not, write to the Free Software 240 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA 241 | 242 | 243 | Also add information on how to contact you by electronic and paper mail. 244 | 245 | If the program is interactive, make it output a short notice like this 246 | when it starts in an interactive mode: 247 | 248 | Gnomovision version 69, Copyright (C) 19xx name of author 249 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 250 | This is free software, and you are welcome to redistribute it 251 | under certain conditions; type `show c' for details. 252 | 253 | The hypothetical commands `show w' and `show c' should show the 254 | appropriate parts of the General Public License. Of course, the 255 | commands you use may be called something other than `show w' and `show 256 | c'; they could even be mouse-clicks or menu items--whatever suits your 257 | program. 258 | 259 | You should also get your employer (if you work as a programmer) or your 260 | school, if any, to sign a "copyright disclaimer" for the program, if 261 | necessary. Here a sample; alter the names: 262 | 263 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 264 | program `Gnomovision' (a program to direct compilers to make passes 265 | at assemblers) written by James Hacker. 266 | 267 | , 1 April 1989 268 | Ty Coon, President of Vice 269 | 270 | That's all there is to it! 271 | 272 | 273 | --- The Artistic License 1.0 --- 274 | 275 | This software is Copyright (c) 2010 by Olaf Alders. 276 | 277 | This is free software, licensed under: 278 | 279 | The Artistic License 1.0 280 | 281 | The Artistic License 282 | 283 | Preamble 284 | 285 | The intent of this document is to state the conditions under which a Package 286 | may be copied, such that the Copyright Holder maintains some semblance of 287 | artistic control over the development of the package, while giving the users of 288 | the package the right to use and distribute the Package in a more-or-less 289 | customary fashion, plus the right to make reasonable modifications. 290 | 291 | Definitions: 292 | 293 | - "Package" refers to the collection of files distributed by the Copyright 294 | Holder, and derivatives of that collection of files created through 295 | textual modification. 296 | - "Standard Version" refers to such a Package if it has not been modified, 297 | or has been modified in accordance with the wishes of the Copyright 298 | Holder. 299 | - "Copyright Holder" is whoever is named in the copyright or copyrights for 300 | the package. 301 | - "You" is you, if you're thinking about copying or distributing this Package. 302 | - "Reasonable copying fee" is whatever you can justify on the basis of media 303 | cost, duplication charges, time of people involved, and so on. (You will 304 | not be required to justify it to the Copyright Holder, but only to the 305 | computing community at large as a market that must bear the fee.) 306 | - "Freely Available" means that no fee is charged for the item itself, though 307 | there may be fees involved in handling the item. It also means that 308 | recipients of the item may redistribute it under the same conditions they 309 | received it. 310 | 311 | 1. You may make and give away verbatim copies of the source form of the 312 | Standard Version of this Package without restriction, provided that you 313 | duplicate all of the original copyright notices and associated disclaimers. 314 | 315 | 2. You may apply bug fixes, portability fixes and other modifications derived 316 | from the Public Domain or from the Copyright Holder. A Package modified in such 317 | a way shall still be considered the Standard Version. 318 | 319 | 3. You may otherwise modify your copy of this Package in any way, provided that 320 | you insert a prominent notice in each changed file stating how and when you 321 | changed that file, and provided that you do at least ONE of the following: 322 | 323 | a) place your modifications in the Public Domain or otherwise make them 324 | Freely Available, such as by posting said modifications to Usenet or an 325 | equivalent medium, or placing the modifications on a major archive site 326 | such as ftp.uu.net, or by allowing the Copyright Holder to include your 327 | modifications in the Standard Version of the Package. 328 | 329 | b) use the modified Package only within your corporation or organization. 330 | 331 | c) rename any non-standard executables so the names do not conflict with 332 | standard executables, which must also be provided, and provide a separate 333 | manual page for each non-standard executable that clearly documents how it 334 | differs from the Standard Version. 335 | 336 | d) make other distribution arrangements with the Copyright Holder. 337 | 338 | 4. You may distribute the programs of this Package in object code or executable 339 | form, provided that you do at least ONE of the following: 340 | 341 | a) distribute a Standard Version of the executables and library files, 342 | together with instructions (in the manual page or equivalent) on where to 343 | get the Standard Version. 344 | 345 | b) accompany the distribution with the machine-readable source of the Package 346 | with your modifications. 347 | 348 | c) accompany any non-standard executables with their corresponding Standard 349 | Version executables, giving the non-standard executables non-standard 350 | names, and clearly documenting the differences in manual pages (or 351 | equivalent), together with instructions on where to get the Standard 352 | Version. 353 | 354 | d) make other distribution arrangements with the Copyright Holder. 355 | 356 | 5. You may charge a reasonable copying fee for any distribution of this 357 | Package. You may charge any fee you choose for support of this Package. You 358 | may not charge a fee for this Package itself. However, you may distribute this 359 | Package in aggregate with other (possibly commercial) programs as part of a 360 | larger (possibly commercial) software distribution provided that you do not 361 | advertise this Package as a product of your own. 362 | 363 | 6. The scripts and library files supplied as input to or produced as output 364 | from the programs of this Package do not automatically fall under the copyright 365 | of this Package, but belong to whomever generated them, and may be sold 366 | commercially, and may be aggregated with this Package. 367 | 368 | 7. C or perl subroutines supplied by you and linked into this Package shall not 369 | be considered part of this Package. 370 | 371 | 8. The name of the Copyright Holder may not be used to endorse or promote 372 | products derived from this software without specific prior written permission. 373 | 374 | 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED 375 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 376 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 377 | 378 | The End 379 | 380 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # metacpan-examples 2 | 3 | This repository contains sample code to get you up and running quickly with the MetaCPAN API. 4 | 5 | ## Please use MetaCPAN::Client 6 | 7 | There are many different ways and clients which you can use to access the API. However, *we strongly encourage you* to start by using the MetaCPAN::Client module. If you have compelling reasons to use a different client, feel free to do so, but please be aware that MetaCPAN::Client is fully supported by MetaCPAN. You will likely save yourself (and us) much debugging time if you begin with this module rather than rolling your own Elasticsearch queries. If MetaCPAN::Client *doesn't* do something which you need it to do, please open a GitHub issue to let us know about it. 8 | 9 | There are some examples to be found here which use `curl`, `WWW::Mechanize`, `Search::Elasticsearch` etc. These are useful for reference, but please do take `MetaCPAN::Client` as your starting point. 10 | 11 | ## Getting Started 12 | 13 | Scripts are all found in /scripts. You can run the Perl scripts in the usual manner, 14 | but if you want to get up and running quickly, you are encouraged to run your 15 | scripts via Carton. The workflow is: 16 | 17 | cpanm Carton 18 | carton install 19 | bin/carton scripts/author/1a-search-authors.pl 20 | 21 | Or, you can use Carton directly: 22 | 23 | carton exec perl -Ilib scripts/author/1a-search-authors.pl 24 | 25 | Using the `bin/carton` will save you a few keystrokes and will 26 | automatically add new libs to the path in future, if they are required. Use 27 | the workflow you are most comfortable with. 28 | 29 | Please open issues for examples you would like to see and send pull requests 30 | for examples you've already written. 31 | 32 | ## Upgrading from v0 33 | 34 | The MetaCPAN API v1 is now available. v0 will be deprecated after a 6 month window. This window closes on or after June 1, 2017. Here's a guide to converting your scripts. 35 | 36 | ## Elasticsearch version 37 | 38 | v1 of the MetaCPAN API uses [Elasticsearch v2.4.0](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/index.html) (v0 was at 0.20.2). There are many breaking changes in this upgrade, since it spans almost 4 years. 39 | 40 | The MetaCPAN API versions will increase with breaking changes, but we will not use the same versioning as Elasticsearch itself. 41 | 42 | ### Data Structure Changes 43 | 44 | Elasticsearch 1.x changed the data structure returned when fields are used. 45 | For example before one could get a `ArrayRef[ HashRef [ Str ] ]` where now 46 | that will come in the form of `ArrayRef[ HashRef [ ArrayRef [ Str ] ] ]`. 47 | 48 | Our convenience endpoints revert this behaviour, but if you're crafting your own searches, you should be aware that the structure of your fields data may have changed. 49 | 50 | ### Client-specific Changes 51 | 52 | #### MetaCPAN::Client 53 | 54 | v0: 55 | 56 | ```perl 57 | use MetaCPAN::Client->new(); 58 | ``` 59 | 60 | v1: 61 | 62 | ```perl 63 | use MetaCPAN::Client->new( version => 'v1' ); 64 | ``` 65 | 66 | #### Search::Elasticsearch 67 | 68 | v0: 69 | 70 | ```perl 71 | use Search::Elasticsearch; 72 | my $es = Search::Elasticsearch->new( 73 | cxn_pool => 'Static::NoPing', 74 | nodes => 'api.metacpan.org', 75 | trace_to => 'Stdout', 76 | ); 77 | ``` 78 | 79 | v1: 80 | 81 | ```perl 82 | use Search::Elasticsearch; 83 | my $es = Search::Elasticsearch->new( 84 | cxn_pool => 'Static::NoPing', 85 | nodes => 'https://fastapi.metacpan.org/v1', 86 | send_get_body_as => 'POST', 87 | trace_to => 'Stdout', 88 | ); 89 | ``` 90 | 91 | * The node URL of the v1 API is https://fastapi.metacpan.org/v1 Note that not 92 | only is the host name new, but we've also switched to https and also added 93 | the version to the path. 94 | 95 | * You'll need to set `send_get_body_as => 'POST'`. This is because v1 does not accept `GET` with a body. 96 | 97 | ##### $es->search 98 | 99 | ```perl 100 | my $faves = $es->search( 101 | index => 'v0', 102 | type => 'favorite', 103 | body => { 104 | query => { match_all => {} }, 105 | facets => { 106 | dist => { 107 | terms => { field => 'favorite.distribution', size => 10 }, 108 | }, 109 | }, 110 | }, 111 | size => 0, 112 | ); 113 | ``` 114 | 115 | ```perl 116 | my $faves = es()->search( 117 | index => 'cpan', 118 | type => 'favorite', 119 | body => { 120 | aggs => { 121 | dist => { 122 | terms => { field => 'distribution', size => 10 }, 123 | }, 124 | }, 125 | }, 126 | ); 127 | ``` 128 | 129 | * The index name is now `cpan` 130 | * `match_all` is the default query type, so it's not required to specify it 131 | * `facets` have been replaced by `aggs` 132 | * The data structure returned for `facets` does not mirror the `aggs` return values, so you'll need to rework your logic when checking the return values. 133 | * When searching on a type (`favorite` in this case), do not prefix the key with the type name. So, as seen above, `field => 'favorite.distribution'` is now `field => 'distribution'` 134 | 135 | #### GET via command line or browser 136 | 137 | v0: `http://api.metacpan.org/v0/author/MSTROUT` 138 | 139 | v1: `https://fastapi.metacpan.org/v1/author/MSTROUT` 140 | 141 | * Note the new host name 142 | * Note that we now use HTTPS 143 | * Note that the path begins with v1 rather than v0 144 | -------------------------------------------------------------------------------- /bin/carton: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | carton exec perl -Ilib -- $@ 4 | -------------------------------------------------------------------------------- /cpanfile: -------------------------------------------------------------------------------- 1 | requires 'CHI'; 2 | requires 'Data::Printer'; 3 | requires 'Data::Printer::Filter::JSON'; 4 | requires 'Data::Printer::Filter::URI'; 5 | requires 'DateTime'; 6 | requires 'HTTP::Tiny::Mech'; 7 | requires 'IO::Socket::SSL'; 8 | requires 'JSON::MaybeXS'; 9 | requires 'MetaCPAN::API::Tiny'; 10 | requires 'MetaCPAN::Client', '>= 2.000000'; 11 | requires 'Search::Elasticsearch'; 12 | requires 'Search::Elasticsearch::Client::2_0::Direct'; 13 | requires 'Sub::Exporter'; 14 | requires 'WWW::Mechanize::Cached'; 15 | requires 'WWW::Mechanize::Cached::GZip'; 16 | 17 | author_requires 'Code::TidyAll'; 18 | -------------------------------------------------------------------------------- /git/hooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | # Hack to use carton's local::lib; 6 | use lib 'local/lib/perl5'; 7 | 8 | use Code::TidyAll::Git::Precommit; 9 | Code::TidyAll::Git::Precommit->check(); 10 | -------------------------------------------------------------------------------- /git/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | chmod +x git/hooks/pre-commit 4 | cd .git/hooks 5 | ln -s ../../git/hooks/pre-commit 6 | -------------------------------------------------------------------------------- /lib/MetaCPAN/Util.pm: -------------------------------------------------------------------------------- 1 | package MetaCPAN::Util; 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use constant DEBUG => !!$ENV{METACPAN_EXAMPLES_DEBUG}; 7 | 8 | use Search::Elasticsearch; 9 | use Sub::Exporter -setup => { exports => ['es'] }; 10 | 11 | sub es { 12 | return Search::Elasticsearch->new( 13 | client => '2_0::Direct', 14 | cxn_pool => 'Static::NoPing', 15 | nodes => 'https://fastapi.metacpan.org/v1', 16 | send_get_body_as => 'POST', 17 | ( trace_to => 'Stdout' ) x !!(DEBUG), 18 | ); 19 | } 20 | 21 | 1; 22 | 23 | =head1 NAME 24 | 25 | MetaCPAN::Util - Utilities for accessing MetaCPAN 26 | 27 | =head1 DESCRIPTION 28 | 29 | Provides shared utility code for examples. 30 | 31 | =head1 FUNCTIONS 32 | 33 | =head2 es 34 | 35 | Returns a L client configured for use with the 36 | MetaCPAN API endpoint. 37 | 38 | =head1 ENVIRONMENT 39 | 40 | =over 4 41 | 42 | =item C 43 | 44 | When set to C<1>, enables output of verbose debugging information. 45 | 46 | =back 47 | 48 | =cut 49 | -------------------------------------------------------------------------------- /scripts/author/1-fetch-single-author-curl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | curl https://fastapi.metacpan.org/v1/author/MSTROUT 4 | -------------------------------------------------------------------------------- /scripts/author/1-fetch-single-author-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $author = es->get( 12 | index => 'cpan', 13 | type => 'author', 14 | id => 'MSTROUT', 15 | ); 16 | 17 | p $author; 18 | -------------------------------------------------------------------------------- /scripts/author/1-fetch-single-author-www-mech-cached.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use WWW::Mechanize::Cached::GZip; 8 | my $mech = WWW::Mechanize::Cached::GZip->new; 9 | $mech->get('https://fastapi.metacpan.org/v1/author/MSTROUT'); 10 | 11 | say $mech->content; 12 | -------------------------------------------------------------------------------- /scripts/author/1-fetch-single-author.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use MetaCPAN::Client; 8 | 9 | my $mcpan = MetaCPAN::Client->new( version => 'v1' ); 10 | my $author = $mcpan->author('MSTROUT'); 11 | 12 | p $author; 13 | -------------------------------------------------------------------------------- /scripts/author/1a-search-authors.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use Data::Printer; 8 | use MetaCPAN::Client; 9 | 10 | my $mc = MetaCPAN::Client->new( version => 'v1' ); 11 | 12 | my $search = $mc->author( { name => 'Olaf *' } ); 13 | 14 | say "raw results"; 15 | say '#' x 80; 16 | while ( my $author = $search->next ) { 17 | p $author; 18 | } 19 | 20 | say '#' x 80; 21 | say 'Total matches: ' . $search->total; 22 | -------------------------------------------------------------------------------- /scripts/author/1b-scroll-all-authors-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $scroller = es()->scroll_helper( 11 | search_type => 'scan', 12 | scroll => '5m', 13 | index => 'cpan', 14 | type => 'author', 15 | size => 100, 16 | body => { 17 | query => { 18 | match_all => {} 19 | } 20 | } 21 | ); 22 | 23 | while ( my $result = $scroller->next ) { 24 | p $result->{_source}; 25 | } 26 | 27 | =pod 28 | 29 | =head1 DESCRIPTION 30 | 31 | This script uses the Search::Elasticsearch::Scroll scrolling API. It provides you with an 32 | iterator and fetches new batches of results as the are needed. This particular 33 | example will iterate over every CPAN author. The size is quite low, so that 34 | you don't get overwhelmed with debugging data when first running this script. 35 | For your purposes, you will likely want to try a greater size. Depending on 36 | your purposes, you may want to set a size of up to 5,000 in order to cut down 37 | on the number of requests required to fetch all authors. 38 | 39 | From the ElasticSearch documentation: 40 | 41 | =over 4 42 | 43 | The scroll parameter controls the keep alive time of the scrolling request and 44 | initiates the scrolling process. The timeout applies per round trip (i.e. 45 | between the previous scan scroll request, to the next). 46 | 47 | =back 48 | 49 | =cut 50 | -------------------------------------------------------------------------------- /scripts/author/1c-scroll-all-authors-with-twitter-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $scroller = es()->scroll_helper( 11 | search_type => 'scan', 12 | scroll => '5m', 13 | index => 'cpan', 14 | type => 'author', 15 | size => 100, 16 | body => { 17 | query => { 18 | filtered => { 19 | filter => { match => { 'profile.name' => 'twitter' } }, 20 | }, 21 | }, 22 | }, 23 | ); 24 | 25 | while ( my $result = $scroller->next ) { 26 | my $author = $result->{_source}; 27 | 28 | foreach my $profile ( @{ $author->{profile} } ) { 29 | next unless $profile->{name} eq 'twitter'; 30 | 31 | p 'Tweet ' . $author->{pauseid} . ' @' . $profile->{id}; 32 | last; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /scripts/author/2-twitter-or-github-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $scroller = es()->scroll_helper( 11 | search_type => 'scan', 12 | scroll => '5m', 13 | index => 'cpan', 14 | type => 'author', 15 | size => 100, 16 | body => { 17 | query => { 18 | filtered => { 19 | filter => { 20 | or => [ 21 | { 22 | and => [ 23 | { 24 | term => { 25 | 'profile.name' => 'twitter' 26 | } 27 | }, 28 | { term => { 'country' => 'US' } } 29 | ] 30 | }, 31 | { 32 | and => [ 33 | { 34 | term => { 'profile.name' => 'github' } 35 | }, 36 | { term => { 'country' => 'CA' } } 37 | ] 38 | }, 39 | ], 40 | } 41 | }, 42 | } 43 | }, 44 | ); 45 | 46 | while ( my $result = $scroller->next ) { 47 | my $author = $result->{_source}; 48 | 49 | foreach my $profile ( @{ $author->{profile} } ) { 50 | if ( $author->{country} eq 'CA' ) { 51 | next unless $profile->{name} eq 'github'; 52 | } 53 | else { 54 | next unless $profile->{name} eq 'twitter'; 55 | } 56 | 57 | say sprintf( 58 | 'author %s country %s %s %s', 59 | $author->{pauseid}, $author->{country}, 60 | $profile->{name}, $profile->{id} 61 | ); 62 | last; 63 | } 64 | } 65 | 66 | =pod 67 | 68 | Demonstrates ANDs nested inside an OR. 69 | 70 | =cut 71 | -------------------------------------------------------------------------------- /scripts/author/twitter.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use MetaCPAN::Client; 8 | 9 | my $mc = MetaCPAN::Client->new( version => 'v1' ); 10 | 11 | # Search for authors with a listed Twitter account 12 | my $search = $mc->author( { 'profile.name' => 'twitter' } ); 13 | 14 | my @handles; 15 | while ( my $author = $search->next ) { 16 | 17 | # grep matching author profiles to extract only the Twitter id 18 | my @profiles = grep { $_->{name} eq 'twitter' } @{ $author->profile }; 19 | 20 | foreach my $profile (@profiles) { 21 | my $id = $profile->{id}; 22 | 23 | # not every handle returned by the API is prefixed by "@", so 24 | # we'll add it when it's missing 25 | $id = '@' . $id unless $id =~ m{\A@}; 26 | push @handles, $id; 27 | } 28 | } 29 | 30 | # print a case-insensitive alpha-sorted list for humans to enjoy 31 | say $_ for sort { "\L$a" cmp "\L$b" } @handles; 32 | 33 | =pod 34 | 35 | =head1 SYNOPSIS 36 | 37 | To create your own Twitter list of CPAN authors install and configure 38 | L 39 | 40 | Then run: 41 | 42 | t list create cpan-authors 43 | perl scripts/author/twitter.pl | xargs t list add cpan-authors 44 | t list cpan-authors members 45 | 46 | =cut 47 | -------------------------------------------------------------------------------- /scripts/distribution/1-bugs-for-dist-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $dist = es()->get( 11 | index => 'cpan', 12 | type => 'distribution', 13 | id => 'Moose', 14 | ); 15 | 16 | p $dist->{bugs}; 17 | -------------------------------------------------------------------------------- /scripts/distribution/2-dists-with-rt-source.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use MetaCPAN::Client; 8 | 9 | my $mc = MetaCPAN::Client->new( version => 'v1' ); 10 | 11 | my $search = $mc->all( 'distributions', 12 | { es_filter => { exists => { field => 'bugs.rt.source' } } } ); 13 | 14 | while ( my $dist = $search->next ) { 15 | p $dist; 16 | } 17 | -------------------------------------------------------------------------------- /scripts/favorite/1-last-50-favorited-dists-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $faves = es()->search( 11 | index => 'cpan', 12 | type => 'favorite', 13 | body => { 14 | query => { match_all => {} }, 15 | sort => [ { date => 'desc' } ], 16 | }, 17 | size => 50, 18 | ); 19 | 20 | my @dists = map { $_->{_source} } @{ $faves->{hits}->{hits} }; 21 | 22 | p @dists; 23 | -------------------------------------------------------------------------------- /scripts/favorite/1a-last-100-favorited-dists-by-user-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $id = shift @ARGV; 11 | 12 | die "usage: ./bin/carton $0 \$user_id" if !$id; 13 | 14 | my $faves = es()->search( 15 | index => 'cpan', 16 | type => 'favorite', 17 | body => { 18 | query => { 19 | filtered => { 20 | query => { match_all => {} }, 21 | filter => { term => { 'user' => $id } } 22 | }, 23 | }, 24 | sort => [ { date => 'desc' } ], 25 | }, 26 | size => 100, 27 | ); 28 | 29 | my @dists = map { $_->{_source} } @{ $faves->{hits}->{hits} }; 30 | 31 | p @dists; 32 | -------------------------------------------------------------------------------- /scripts/favorite/2-favorites-previous-month-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use DateTime; 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $now = DateTime->now; 12 | my $then = $now->clone->subtract( months => 1 ); 13 | 14 | my $faves = es()->search( 15 | index => 'cpan', 16 | type => 'favorite', 17 | body => { 18 | query => { 19 | filtered => { 20 | filter => { 21 | range => { 22 | date => 23 | { from => $then->datetime, to => $now->datetime } 24 | }, 25 | }, 26 | }, 27 | }, 28 | }, 29 | size => 400, 30 | ); 31 | 32 | my @dists = map { $_->{_source} } @{ $faves->{hits}->{hits} }; 33 | 34 | p @dists; 35 | -------------------------------------------------------------------------------- /scripts/favorite/3-leaderboard-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $faves = es()->search( 11 | index => 'cpan', 12 | type => 'favorite', 13 | body => { 14 | aggs => { 15 | dist => { 16 | terms => { field => 'distribution', size => 10 }, 17 | }, 18 | }, 19 | }, 20 | ); 21 | 22 | my @counts = map { +{ $_->{key} => $_->{doc_count} } } 23 | @{ $faves->{aggregations}->{dist}->{buckets} }; 24 | p @counts; 25 | 26 | __END__ 27 | =pod 28 | 29 | =head1 DESCRIPTION 30 | 31 | Get the 10 distributions with the most ++ clicks, sorted by descending 32 | popularity. 33 | 34 | =cut 35 | -------------------------------------------------------------------------------- /scripts/favorite/4-leaderboard-previous-month-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use DateTime; 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $now = DateTime->now; 12 | my $then = $now->clone->subtract( months => 1 ); 13 | 14 | my $faves = es()->search( 15 | index => 'cpan', 16 | type => 'favorite', 17 | body => { 18 | query => { 19 | filtered => { 20 | filter => { 21 | range => { 22 | date => 23 | { from => $then->datetime, to => $now->datetime } 24 | }, 25 | }, 26 | }, 27 | }, 28 | aggs => { 29 | dist => { 30 | terms => { field => 'distribution', size => 50 }, 31 | }, 32 | }, 33 | }, 34 | size => 0, 35 | ); 36 | 37 | my @dists = @{ $faves->{aggregations}{dist}{buckets} }; 38 | 39 | p @dists; 40 | -------------------------------------------------------------------------------- /scripts/favorite/5-plus-plus-your-favorites-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use HTTP::Tiny (); 8 | use JSON::MaybeXS qw( encode_json ); 9 | use lib './lib'; 10 | use MetaCPAN::Util qw( es ); 11 | 12 | my $token = shift @ARGV; 13 | my @modules = @ARGV; 14 | 15 | die "Usage: ./bin/carton $0 secret_token Moose DBIx::Class ...\n" 16 | unless @modules; 17 | 18 | my $module = es()->search( 19 | index => 'cpan', 20 | type => 'file', 21 | fields => 'release', 22 | size => scalar @modules, 23 | body => { 24 | query => { 25 | filtered => { 26 | filter => { 27 | bool => { 28 | 29 | # a module is a file 30 | must => [ 31 | { term => { 'authorized' => 'true' } }, 32 | { terms => { 'module.name' => \@modules } }, 33 | { term => { 'status' => 'latest' } } 34 | ] 35 | }, 36 | }, 37 | }, 38 | }, 39 | }, 40 | ); 41 | 42 | my @release_names 43 | = map { $_->{fields}->{release} } @{ $module->{hits}->{hits} }; 44 | 45 | my $release = es()->search( 46 | index => 'cpan', 47 | type => 'release', 48 | size => scalar @release_names, 49 | body => { 50 | query => { 51 | filtered => { 52 | filter => { terms => { 'name' => \@release_names } }, 53 | }, 54 | }, 55 | }, 56 | ); 57 | 58 | foreach my $hit ( @{ $release->{hits}->{hits} } ) { 59 | plus_plus( 60 | { 61 | author => $hit->{_source}->{author}, 62 | distribution => $hit->{_source}->{distribution}, 63 | release => $hit->{_source}->{name}, 64 | } 65 | ); 66 | } 67 | 68 | sub plus_plus { 69 | my $params = shift; 70 | my $ua = HTTP::Tiny->new; 71 | my $res = $ua->post( 72 | "https://fastapi.metacpan.org/v1/user/favorite?access_token=$token", 73 | { 74 | content => encode_json($params), 75 | headers => { 'content-type' => 'application/json' } 76 | }, 77 | ); 78 | p $res; 79 | } 80 | 81 | =pod 82 | 83 | =head1 DESCRIPTION 84 | 85 | Given a MetaCPAN secret token and a list of one or more modules, favorite these 86 | in the user's MetaCPAN account. 87 | 88 | See L 89 | 90 | =cut 91 | -------------------------------------------------------------------------------- /scripts/favorite/6-list-plussers-by-module.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use MetaCPAN::Client; 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | binmode( STDOUT, ":utf8" ); 12 | 13 | my $module_name = shift @ARGV; 14 | 15 | die "Usage: ./bin/carton $0 HTML::Restrict\n" unless $module_name; 16 | 17 | my $module = MetaCPAN::Client->new->module($module_name); 18 | 19 | my $plussers = es()->search( 20 | index => 'cpan', 21 | type => 'favorite', 22 | size => 1000, 23 | body => { 24 | query => { 25 | filtered => { 26 | filter => { 27 | term => { 'distribution' => $module->distribution } 28 | }, 29 | }, 30 | }, 31 | fields => ['user'], 32 | }, 33 | ); 34 | 35 | my @ids = map { $_->{fields}->{user} } @{ $plussers->{hits}->{hits} }; 36 | my $total = @ids; 37 | 38 | my $authors = es()->search( 39 | index => 'cpan', 40 | type => 'author', 41 | size => scalar @ids, 42 | body => { 43 | query => { 44 | filtered => { 45 | query => { match_all => {} }, 46 | filter => { terms => { 'user' => \@ids } }, 47 | }, 48 | }, 49 | fields => [ 'pauseid', 'name' ], 50 | sort => ['pauseid'], 51 | }, 52 | ); 53 | 54 | foreach my $hit ( @{ $authors->{hits}->{hits} } ) { 55 | say $hit->{fields}->{pauseid} . ' - ' . $hit->{fields}->{name}; 56 | } 57 | 58 | my $found = @{ $authors->{hits}->{hits} }; 59 | say "Found $found out of $total users"; 60 | 61 | =pod 62 | 63 | =head1 DESCRIPTION 64 | 65 | Given a module name, return the names of PAUSE author's who have clicked ++ on 66 | the distribution this module belongs to. 67 | 68 | =cut 69 | -------------------------------------------------------------------------------- /scripts/file/1-get-files-in-dist-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use Data::Printer; 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $files = es()->search( 12 | index => 'cpan', 13 | type => 'file', 14 | size => 300, 15 | body => { 16 | query => { 17 | filtered => { 18 | query => { match_all => {} }, 19 | filter => { 20 | bool => { 21 | must => { 22 | term => { 'release' => 'HTML-Restrict-2.1.5' }, 23 | }, 24 | must_not => { term => { 'directory' => 'true' }, }, 25 | }, 26 | }, 27 | }, 28 | }, 29 | }, 30 | ); 31 | 32 | my @files = sort map { $_->{_source}->{path} } @{ $files->{hits}->{hits} }; 33 | p @files; 34 | -------------------------------------------------------------------------------- /scripts/file/2-get-dists-with-cpanfile.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use Data::Printer; 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $files = es()->search( 12 | index => 'cpan', 13 | type => 'file', 14 | size => 10, 15 | body => { 16 | query => { 17 | filtered => { 18 | query => { match_all => {} }, 19 | filter => { 20 | and => [ 21 | { term => { 'path' => 'cpanfile' } }, 22 | { term => { 'directory' => \0 } }, 23 | ] 24 | }, 25 | }, 26 | }, 27 | }, 28 | fields => [ 'release', 'author' ], 29 | ); 30 | 31 | my @hits = @{ $files->{hits}->{hits} }; 32 | p @hits; 33 | -------------------------------------------------------------------------------- /scripts/file/3-find-files-in-top-level-by-name.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use Data::Printer; 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $files = es()->search( 12 | index => 'cpan', 13 | type => 'file', 14 | size => 10, 15 | body => { 16 | query => { 17 | filtered => { 18 | filter => { 19 | and => [ 20 | { term => { 'path' => 'cpanfile' } }, 21 | { term => { 'directory' => \0 } }, 22 | ] 23 | }, 24 | }, 25 | }, 26 | }, 27 | fields => [ 'release', 'author' ], 28 | ); 29 | 30 | my @hits = @{ $files->{hits}->{hits} }; 31 | p @hits; 32 | -------------------------------------------------------------------------------- /scripts/file/4-main-search.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use JSON::MaybeXS qw( decode_json ); 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $search_term = shift @ARGV || 'HTML-Re'; 12 | if ( $search_term =~ m{::} ) { 13 | $search_term =~ s{::}{-}g; 14 | } 15 | 16 | my $result = es()->search( 17 | index => 'cpan', 18 | type => 'file', 19 | body => { 20 | query => { 21 | boosting => { 22 | negative_boost => 0.5, 23 | positive => { 24 | bool => { 25 | should => [ 26 | { 27 | term => { 28 | "documentation" => { 29 | boost => 20, 30 | value => $search_term, 31 | } 32 | } 33 | }, 34 | { 35 | term => { 36 | "module.name" => { 37 | boost => 20, 38 | value => $search_term, 39 | }, 40 | } 41 | }, 42 | { 43 | dis_max => { 44 | queries => [ 45 | { 46 | query_string => { 47 | allow_leading_wildcard => 0, 48 | boost => 3, 49 | default_operator => "AND", 50 | fields => [ 51 | "documentation.analyzed^2", 52 | "module.name.analyzed^2", 53 | "distribution.analyzed", 54 | "documentation.camelcase", 55 | "module.name.camelcase", 56 | "distribution.camelcase", 57 | ], 58 | query => $search_term, 59 | use_dis_max => 1, 60 | }, 61 | }, 62 | { 63 | query_string => { 64 | allow_leading_wildcard => 0, 65 | default_operator => "AND", 66 | fields => [ 67 | "abstract.analyzed", 68 | "pod.analyzed" 69 | ], 70 | query => $search_term, 71 | use_dis_max => 1, 72 | }, 73 | }, 74 | ], 75 | } 76 | } 77 | ] 78 | } 79 | }, 80 | negative => { 81 | term => { 82 | "mime" => { value => "text/x-script.perl" } 83 | } 84 | } 85 | } 86 | }, 87 | }, 88 | size => 10, 89 | ); 90 | 91 | my @dists = map { $_->{_source} } @{ $result->{hits}->{hits} }; 92 | 93 | p @dists; 94 | 95 | =pod 96 | 97 | =head1 DESCRIPTION 98 | 99 | This script will provide search result almost like on MetaCPAN main search [https://metacpan.org/search?q=$search_term] 100 | 101 | =cut 102 | -------------------------------------------------------------------------------- /scripts/file/5-size-of-cpan.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use MetaCPAN::Client (); 8 | 9 | my $mc = MetaCPAN::Client->new( version => 'v1' ); 10 | 11 | my $file = $mc->all( 12 | 'files', 13 | { 14 | aggregations => { aggs => { sum => { field => 'stat.size' } } }, 15 | } 16 | ); 17 | p $file->aggregations; 18 | 19 | __END__ 20 | =pod 21 | 22 | =head1 DESCRIPTION 23 | 24 | Get the size of CPAN + BackPAN, when it's unpacked. 25 | 26 | =cut 27 | -------------------------------------------------------------------------------- /scripts/module/1-fetch-single-module-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $module = es()->get( 11 | index => 'cpan', 12 | type => 'module', 13 | id => 'HTML::Restrict', 14 | ); 15 | 16 | p $module; 17 | -------------------------------------------------------------------------------- /scripts/module/3-fetch-modules-in-release.pl: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | use feature qw( say ); 4 | 5 | use MetaCPAN::Client (); 6 | my $client = MetaCPAN::Client->new( version => 'v1' ); 7 | 8 | my $dist = shift @ARGV; 9 | 10 | die "usage: ./bin/carton $0 Moose" unless $dist; 11 | 12 | my $modules = $client->module( 13 | { 14 | all => [ 15 | { authorized => 'true' }, 16 | { binary => 'false' }, 17 | { distribution => $dist }, 18 | { indexed => 'true' }, 19 | { status => 'latest' }, 20 | ] 21 | } 22 | ); 23 | 24 | while ( my $module = $modules->next ) { 25 | next unless $module->module; 26 | for my $pkg ( @{ $module->module } ) { 27 | say $pkg->{name}; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /scripts/permission/aggregate-author-perms.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use CLDR::Number (); 8 | use Cpanel::JSON::XS qw( decode_json ); 9 | use Data::Printer; 10 | use List::Compare (); 11 | use LWP::UserAgent (); 12 | use Math::Round qw( nearest ); 13 | use Parse::CPAN::Packages::Fast (); 14 | use WWW::Mechanize::Cached (); 15 | 16 | my $cldr = CLDR::Number->new( locale => 'en' ); 17 | my $decf = $cldr->decimal_formatter; 18 | my $perf = $cldr->percent_formatter( minimum_fraction_digits => 2 ); 19 | 20 | my @maxmind_authors = ( 21 | 'OALDERS', 'EILARA', 'TJMATHER', 'MATEU', 'OSCHWALD', 'RSRCHBOY', 22 | 'FLORA', 'MARKF', 'RUBEN', 'WDS', 'KLPTWO', 'PCRONIN', 23 | 'ANDYJACK', 'MAXMIND', 24 | ); 25 | my @maxmind_redacted_authors = ( 26 | 'OALDERS', 'EILARA', 'TJMATHER', 'MATEU', 'OSCHWALD', 'RSRCHBOY', 27 | 'MARKF', 'RUBEN', 'WDS', 'KLPTWO', 'PCRONIN', 'ANDYJACK', 28 | ); 29 | 30 | my %PTS = ( 31 | 'qa2010' => [ 32 | 'CHORNY', 'HMBRAND', 'RURBAN', 'MARCEL', 33 | 'BOOK', 'BDFOY', 'ANDYA', 'POTYL', 34 | 'DAXIM', 'ABELTJE', 'OVID', 'HORNBURG', 35 | 'DOMM', 'MIYAGAWA', 'PJCJ', 'BARBIE', 36 | 'FLORA', 'RJBS', 'JKUTEJ', 'SREZIC', 37 | 'MSCHWERN', 'SZABGAB', 'RGIERSIG', 'SQUEEK', 38 | 'PEPL' 39 | ], 40 | 'qa2011' => [ 41 | 'RGE', 'HMBRAND', 'MARCEL', 'SCHWIGON', 42 | 'LEONT', 'BOOK', 'BDFOY', 'ANDYA', 43 | 'AVAR', 'POTYL', 'DAXIM', 'ABELTJE', 44 | 'SMUELLER', 'OVID', 'DOLMEN', 'WESJDJ', 45 | 'SAPER', 'ADAMK', 'PJCJ', 'FLORA', 46 | 'ABIGAIL', 'RJBS', 'PERLER', 'DGL', 47 | 'JKUTEJ', 'WONKO', 'ADIE', 'BURAK' 48 | ], 49 | 'qa2012' => [ 50 | 'XAV', 'HMBRAND', 'CHESSKIT', 'NPEREZ', 51 | 'RGARCIA', 'ELIZABETH', 'DAGOLDEN', 'SCHWIGON', 52 | 'LEONT', 'BOOK', 'BDFOY', 'ANDYA', 53 | 'HAGGAI', 'GETTY', 'DAXIM', 'DDUMONT', 54 | 'ABELTJE', 'OVID', 'ELBEHO', 'WOLFSAGE', 55 | 'DOLMEN', 'WESJDJ', 'PAUAMMA', 'SAPER', 56 | 'OALDERS', 'MIYAGAWA', 'PJCJ', 'BARBIE', 57 | 'FLORA', 'VPIT', 'RJBS', 'DGL', 58 | 'ISHIGAKI', 'WONKO', 'SREZIC', 'MSCHWERN', 59 | 'GARU', 'RIBASUSHI', 'ADIE', 'APEIRON', 60 | 'ANDK' 61 | ], 62 | 'qa2013' => [ 63 | 'PERRETTDL', 'SJN', 'TBSLIVER', 'JROBINSON', 64 | 'MITHALDU', 'HMBRAND', 'ELIZABETH', 'DAGOLDEN', 65 | 'SCHWIGON', 'JKEENAN', 'LEONT', 'BOOK', 66 | 'BANNAN', 'ANDYA', 'DREBOLO', 'PDCAWLEY', 67 | 'GETTY', 'BINGOS', 'ABELTJE', 'REHSACK', 68 | 'BYTEROCK', 'WOLFSAGE', 'DOLMEN', 'BBUSS', 69 | 'PJCJ', 'BARBIE', 'ARC', 'RJBS', 70 | 'DGL', 'ISHIGAKI', 'RIBASUSHI', 'JMASTROS', 71 | 'ANDK', 'NEWELLC' 72 | ], 73 | 'qa2014' => [ 74 | 'SJN', 'ETHER', 'MITHALDU', 'HMBRAND', 75 | 'ELIZABETH', 'DAGOLDEN', 'SCHWIGON', 'LEONT', 76 | 'BOOK', 'DAMS', 'MSTROUT', 'ABELTJE', 77 | 'TIMB', 'FROGGS', 'OVID', 'REHSACK', 78 | 'ELBEHO', 'WOLFSAGE', 'DOLMEN', 'SAPER', 79 | 'OALDERS', 'PJCJ', 'BARBIE', 'RJBS', 80 | 'ISHIGAKI', 'NEILB', 'SREZIC', 'RIBASUSHI', 81 | 'HAARG', 'ANDK' 82 | ], 83 | 'qa2015' => [ 84 | 'SJN', 'ETHER', 'MITHALDU', 'HMBRAND', 85 | 'ELIZABETH', 'DAGOLDEN', 'SCHWIGON', 'LEONT', 86 | 'EXODIST', 'BOOK', 'TADZIK', 'TINITA', 87 | 'ABELTJE', 'INGY', 'FROGGS', 'REHSACK', 88 | 'WOLFSAGE', 'DOLMEN', 'OALDERS', 'WOLLMERS', 89 | 'MIYAGAWA', 'PJCJ', 'BARBIE', 'BARTOLIN', 90 | 'RJBS', 'ISHIGAKI', 'NEILB', 'SREZIC', 91 | 'DRTECH', 'RIBASUSHI', 'LICHTKIND', 'ARISTOTLE', 92 | 'ANDK', 'NINE' 93 | ], 94 | 'qa2016' => [ 95 | 'ETHER', 'HMBRAND', 'LLAP', 'ELIZABETH', 96 | 'SCHWIGON', 'JKEENAN', 'LEONT', 'EXODIST', 97 | 'BOOK', 'TADZIK', 'MICKEY', 'BINGOS', 98 | 'ABELTJE', 'TIMB', 'JBERGER', 'WOLFSAGE', 99 | 'DOLMEN', 'OALDERS', 'PJCJ', 'BARBIE', 100 | 'ARC', 'RJBS', 'ISHIGAKI', 'XSAWYERX', 101 | 'NEILB', 'SREZIC', 'ARISTOTLE', 'SARGIE', 102 | 'ANDK' 103 | ], 104 | 'qa2017' => [ 105 | 'ETHER', 'MITHALDU', 'HMBRAND', 'LEEJO', 106 | 'LLAP', 'SKAJI', 'ELIZABETH', 'LEONT', 107 | 'UGEXE', 'BOOK', 'TODDR', 'PREACTION', 108 | 'TADZIK', 'MICKEY', 'BINGOS', 'TINITA', 109 | 'ABELTJE', 'INGY', 'JBERGER', 'ELBEHO', 110 | 'WOLFSAGE', 'OALDERS', 'MIYAGAWA', 'PJCJ', 111 | 'ARC', 'ETJ', 'ISHIGAKI', 'XSAWYERX', 112 | 'NEILB', 'SREZIC', 'GARU', 'ATOOMIC', 113 | 'ARISTOTLE', 'HAARG', 'ANDK', 'NINE' 114 | ], 115 | ); 116 | 117 | my $ua = LWP::UserAgent->new; 118 | $ua->mirror( 'https://cpan.metacpan.org/modules/02packages.details.txt', 119 | '02packages.details.txt' ); 120 | 121 | my $parser = Parse::CPAN::Packages::Fast->new('02packages.details.txt'); 122 | 123 | say join '|', 124 | ( 125 | q{}, 126 | q{}, 127 | 'Modules with maint', 128 | 'Modules in 02packages', 129 | '% of modules in 02packages', 130 | ); 131 | say join '---', ( ('|') x 5 ); 132 | 133 | for my $author ( sort @{$PTS{qa2017}} ) { 134 | crunch_numbers( $author, [$author]); 135 | } 136 | 137 | for my $group_name ( sort keys %PTS ) { 138 | crunch_numbers( $group_name, $PTS{$group_name} ); 139 | } 140 | 141 | sub crunch_numbers { 142 | my $title = shift; 143 | my $authors = shift; 144 | 145 | # The modules which these authors have release permissions on. 146 | my %perms = get_permissions($authors); 147 | 148 | my $lc = List::Compare->new( [ $parser->packages ], [ keys %perms ] ); 149 | 150 | # The permissioned modules which actually appear in 02packages. 151 | my @covered = $lc->get_intersection; 152 | 153 | my $percent 154 | = nearest( 0.0001, scalar @covered / ( scalar $parser->packages ) ); 155 | 156 | say join '|', $title, $decf->format( scalar keys %perms ), 157 | $decf->format( scalar @covered ), $perf->format($percent); 158 | } 159 | 160 | sub get_permissions { 161 | my $authors = shift; 162 | my $mech = WWW::Mechanize::Cached->new; 163 | 164 | my %modules; 165 | 166 | my $base_url = 'http://fastapi.metacpan.org/v1/permission/by_author'; 167 | foreach my $author ( @{$authors} ) { 168 | my $url = "$base_url/$author"; 169 | $mech->get($url); 170 | my $perms = decode_json( $mech->content ); 171 | 172 | foreach my $perm ( @{ $perms->{permissions} } ) { 173 | push @{ $modules{ $perm->{module_name} } }, $author; 174 | } 175 | } 176 | 177 | return %modules; 178 | } 179 | -------------------------------------------------------------------------------- /scripts/pod/1-fetch-single-pod-doc-as-html.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use MetaCPAN::Client; 8 | 9 | my $mcpan = MetaCPAN::Client->new( version => 'v1' ); 10 | my $html_pod = $mcpan->pod('Carton'); 11 | say $html_pod->html; 12 | -------------------------------------------------------------------------------- /scripts/pod/1a-fetch-single-pod-doc-as-plain-text.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use MetaCPAN::Client( version => 'v1' ); 8 | 9 | my $mcpan = MetaCPAN::Client->new; 10 | my $html_pod = $mcpan->pod('Carton'); 11 | say $html_pod->plain; 12 | -------------------------------------------------------------------------------- /scripts/pod/README: -------------------------------------------------------------------------------- 1 | /pod is a special endpoint. It's not a wrapper around an Search::Elasticsearch type, 2 | so it doesn't return JSON. For this reason we cannot hit this endpoint via 3 | Search::Elasticsearch.pm. 4 | 5 | The default content type is HTML, as created via Pod::Simple::XHTML. Available 6 | content types are: 7 | 8 | text/plain 9 | text/x-pod 10 | text/x-markdown 11 | text/html 12 | 13 | See lib/MetaCPAN/Server/View/Pod.pm in the cpan-api repo for more information. 14 | -------------------------------------------------------------------------------- /scripts/release/1-pkg2url-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $release = es->search( 11 | index => 'cpan', 12 | type => 'release', 13 | body => { 14 | filter => { term => { 'archive' => 'Acme-Hoge-0.03.tar.gz' } }, 15 | }, 16 | ); 17 | 18 | say $release->{hits}{hits}[0]{_source}{download_url}; 19 | -------------------------------------------------------------------------------- /scripts/release/10-all-latest-releases.pl: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | use feature qw( say ); 4 | 5 | use MetaCPAN::Client (); 6 | 7 | my $mc = MetaCPAN::Client->new; 8 | my $release_results = $mc->release( { status => 'latest' } ); 9 | 10 | while ( my $release = $release_results->next ) { 11 | say $release->download_url; 12 | } 13 | -------------------------------------------------------------------------------- /scripts/release/11-all-latest-releases-by-NEILB.pl: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | use feature qw( say ); 4 | 5 | use MetaCPAN::Client (); 6 | 7 | my $mc = MetaCPAN::Client->new; 8 | my $release_results 9 | = $mc->release( 10 | { all => [ { author => 'NEILB', }, { status => 'latest' } ] } ); 11 | 12 | while ( my $release = $release_results->next ) { 13 | say $release->download_url; 14 | } 15 | -------------------------------------------------------------------------------- /scripts/release/12-all-latest-releases-by-NEILB-with-git-repository.pl: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | use feature qw( say ); 4 | 5 | use MetaCPAN::Client (); 6 | 7 | my $mc = MetaCPAN::Client->new; 8 | my $release_results = $mc->release( 9 | { 10 | all => [ 11 | { author => 'NEILB', }, 12 | { status => 'latest' }, 13 | { 'resources.repository.type' => 'git' } 14 | ] 15 | } 16 | ); 17 | 18 | while ( my $release = $release_results->next ) { 19 | say $release->resources->{repository}->{url}; 20 | } 21 | -------------------------------------------------------------------------------- /scripts/release/13-all-releases-in-last-24-hours.pl: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | use feature qw( say ); 4 | 5 | use DateTime (); 6 | use MetaCPAN::Client (); 7 | 8 | my $now = DateTime->now; 9 | my $then = DateTime->now->subtract( days => 1 ); 10 | 11 | my $mc = MetaCPAN::Client->new; 12 | 13 | my $release_set = $mc->all( 14 | 'releases', 15 | { 16 | es_filter => { 17 | range => { date => { from => $then->datetime } }, 18 | }, 19 | } 20 | ); 21 | 22 | while ( my $release = $release_set->next ) { 23 | say $release->download_url; 24 | } 25 | -------------------------------------------------------------------------------- /scripts/release/1a-module2url-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use Search::Elasticsearch; 8 | 9 | use lib './lib'; 10 | use MetaCPAN::Util qw( es ); 11 | 12 | my $module = es->search( 13 | index => 'cpan', 14 | type => 'file', 15 | body => { 16 | query => { match_all => {} }, 17 | filter => { 18 | and => [ 19 | { term => { 'authorized' => 'true' } }, 20 | { term => { 'module.name' => 'Acme::Hoge' } }, 21 | { term => { 'module.version' => '0.03' } } 22 | ] 23 | }, 24 | }, 25 | ); 26 | 27 | my $release_name = $module->{hits}{hits}[0]{_source}{release}; 28 | 29 | my $release = es->search( 30 | index => 'cpan', 31 | type => 'release', 32 | body => { 33 | filter => { term => { 'name' => $release_name } }, 34 | }, 35 | ); 36 | 37 | say $release->{hits}{hits}[0]{_source}{download_url}; 38 | -------------------------------------------------------------------------------- /scripts/release/2-author-upload-leaderboard-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $uploads = es()->search( 12 | index => 'cpan', 13 | type => 'release', 14 | body => { 15 | query => { match_all => {} }, 16 | aggs => { 17 | author => { terms => { field => 'author', size => 10 }, }, 18 | }, 19 | }, 20 | ); 21 | 22 | my @authors = map { +{ $_->{key} => $_->{doc_count} } } 23 | @{ $uploads->{aggregations}->{author}->{buckets} }; 24 | 25 | p @authors; 26 | -------------------------------------------------------------------------------- /scripts/release/3-author-uploads-one-author-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $uploads = es()->search( 11 | index => 'cpan', 12 | type => 'release', 13 | body => { 14 | query => { 15 | filtered => { 16 | filter => { term => { 'author' => 'OALDERS' } }, 17 | }, 18 | }, 19 | aggs => { 20 | author => { terms => { field => 'author', size => 40 }, }, 21 | }, 22 | }, 23 | size => 0, 24 | ); 25 | 26 | use DDP; 27 | p $uploads; 28 | -------------------------------------------------------------------------------- /scripts/release/4-latest-release-versions-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $latest = es()->search( 12 | index => 'cpan', 13 | type => 'release', 14 | fields => [ 'distribution', 'version' ], 15 | size => 3, 16 | body => { 17 | query => { 18 | filtered => { 19 | query => { match_all => {} }, 20 | filter => { 21 | and => [ 22 | { term => { 'status' => 'latest' } }, 23 | { 24 | terms => { 25 | 'distribution' => 26 | [ 'Moose', 'MetaCPAN-API', 'DBIx-Class' ] 27 | }, 28 | }, 29 | ], 30 | }, 31 | }, 32 | }, 33 | } 34 | ); 35 | 36 | my @releases = map { $_->{fields} } @{ $latest->{hits}->{hits} }; 37 | p @releases; 38 | 39 | =pod 40 | 41 | =head1 DESCRIPTION 42 | 43 | This query uses an AND filter to get the latest release of Moose, MetaCPAN-API 44 | and DBIx-Class. Not that the "term" query is looking for an exact match on 45 | "latest". The "terms" query below it is looking for an exact match on *any* of 46 | the release names in the list. So, the "terms" query functions as an OR. In 47 | terms of SQL, you could write this logic using an "OR" or an "IN". 48 | 49 | A release can have one of 3 valid status: latest, cpan or backpan. 50 | 51 | =over 4 52 | 53 | =item latest 54 | 55 | This is the latest, authorized version of this release. 56 | 57 | =item cpan 58 | 59 | This release is currently on CPAN. Check the "authorized" field if you want 60 | only authorized releases. 61 | 62 | =item backpan 63 | 64 | This release is no longer on CPAN and is currently on BackPAN. Check the 65 | "authorized" field if you want only authorized releases. 66 | 67 | =back 68 | 69 | =cut 70 | -------------------------------------------------------------------------------- /scripts/release/4a-latest-release-versions-bool-filter-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $latest = es()->search( 11 | index => 'cpan', 12 | type => 'release', 13 | fields => [ 'distribution', 'version' ], 14 | size => 4, 15 | body => { 16 | query => { 17 | filtered => { 18 | filter => { 19 | bool => { 20 | must => [ 21 | { term => { 'status' => 'latest' } }, 22 | { 23 | terms => { 24 | 'distribution' => [ 25 | 'Moose', 'MetaCPAN-Client', 26 | 'DBIx-Class', 'Moo', 27 | ] 28 | }, 29 | }, 30 | ], 31 | must_not => { term => { 'author' => 'ETHER' } }, 32 | }, 33 | }, 34 | }, 35 | }, 36 | }, 37 | ); 38 | 39 | my @releases = map { $_->{fields} } @{ $latest->{hits}->{hits} }; 40 | p @releases; 41 | 42 | =pod 43 | 44 | =head1 DESCRIPTION 45 | 46 | This example is much like the previous example, but in this case we've opted 47 | for a "bool" filter rather than an "AND" filter. The "bool" filter accepts the 48 | following parameters: "must", "must_not" and "should". Boolean filters are 49 | preferred over AND, OR and NOT filters because they can make better choices 50 | about how to combine filters optimally. 51 | 52 | =cut 53 | -------------------------------------------------------------------------------- /scripts/release/5-latest-releases-by-author-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my $author = shift @ARGV; 12 | die "usage: $0 PAUSEID" if !$author; 13 | 14 | my $latest = es()->search( 15 | index => 'cpan', 16 | type => 'release', 17 | fields => [ 'distribution', 'provides', 'version' ], 18 | size => 500, 19 | body => { 20 | query => { 21 | filtered => { 22 | query => { match_all => {} }, 23 | filter => { 24 | and => [ 25 | { term => { 'status' => 'latest' } }, 26 | { term => { 'author' => $author }, }, 27 | ], 28 | }, 29 | }, 30 | }, 31 | sort => [ { 'date' => 'desc' } ], 32 | }, 33 | ); 34 | 35 | my @releases = map { $_->{fields} } @{ $latest->{hits}->{hits} }; 36 | p @releases; 37 | 38 | =pod 39 | 40 | =head1 DESCRIPTION 41 | 42 | This query uses an AND filter to get the latest release by an AUTHOR. Note 43 | that since this is looking for "latest", it will only return releases for which 44 | this author was the last to upload an authorized version. 45 | 46 | A release can have one of 3 valid status: latest, cpan or backpan. 47 | 48 | =over 4 49 | 50 | =item latest 51 | 52 | This is the latest, authorized version of this release. 53 | 54 | =item cpan 55 | 56 | This release is currently on CPAN. Check the "authorized" field if you want 57 | only authorized releases. 58 | 59 | =item backpan 60 | 61 | This release is no longer on CPAN and is currently on BackPAN. Check the 62 | "authorized" field if you want only authorized releases. 63 | 64 | =back 65 | 66 | =cut 67 | -------------------------------------------------------------------------------- /scripts/release/6-latest-releases-with-git-repo-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use Data::Printer; 8 | use lib './lib'; 9 | use MetaCPAN::Util qw( es ); 10 | 11 | my @must = ( 12 | { term => { 'resources.repository.type' => 'git' }, }, 13 | { term => { status => 'latest' } }, 14 | { term => { authorized => 'true' } }, 15 | ); 16 | 17 | my $scroller = es()->scroll_helper( 18 | body => { 19 | query => { 20 | bool => { must => \@must }, 21 | }, 22 | }, 23 | _source => [ 'author', 'date', 'distribution', 'name', 'resources' ], 24 | search_type => 'scan', 25 | scroll => '5m', 26 | index => 'cpan', 27 | type => 'release', 28 | size => 500, 29 | ); 30 | 31 | while ( my $result = $scroller->next ) { 32 | my $release = $result->{_source}; 33 | } 34 | -------------------------------------------------------------------------------- /scripts/release/7-all-releases-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use Data::Printer; 8 | 9 | use lib './lib'; 10 | use MetaCPAN::Util qw( es ); 11 | 12 | my $scroller = es()->scroll_helper( 13 | search_type => 'scan', 14 | scroll => '5m', 15 | index => 'cpan', 16 | type => 'release', 17 | size => 1_000, 18 | body => { fields => ['download_url'] }, 19 | ); 20 | 21 | my @urls; 22 | while ( my $result = $scroller->next ) { 23 | push @urls, $result->{fields}->{download_url}; 24 | } 25 | -------------------------------------------------------------------------------- /scripts/release/7-all-releases.pl: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | use feature qw( say ); 4 | 5 | use MetaCPAN::Client (); 6 | 7 | my $mc = MetaCPAN::Client->new; 8 | my $release_results = $mc->all('releases'); 9 | 10 | while ( my $release = $release_results->next ) { 11 | say $release->download_url; 12 | } 13 | -------------------------------------------------------------------------------- /scripts/release/8-all-releases-by-author-es.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use lib './lib'; 8 | use MetaCPAN::Util qw( es ); 9 | 10 | my $uploads = es()->search( 11 | index => 'cpan', 12 | type => 'release', 13 | body => { 14 | query => { 15 | filtered => { 16 | filter => { term => { 'author' => 'OALDERS' } }, 17 | }, 18 | }, 19 | fields => [ 'author', 'archive', 'date' ], 20 | sort => [ { "date" => "desc" } ], 21 | }, 22 | size => 100, 23 | ); 24 | 25 | my @releases = map { $_->{fields} } @{ $uploads->{hits}->{hits} }; 26 | use DDP; 27 | p @releases; 28 | -------------------------------------------------------------------------------- /scripts/release/9-all-releases-excluding-backpan.pl: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | use feature qw( say ); 4 | 5 | use MetaCPAN::Client (); 6 | 7 | my $mc = MetaCPAN::Client->new; 8 | my $release_results = $mc->release( { not => { status => 'backpan' } } ); 9 | 10 | while ( my $release = $release_results->next ) { 11 | say $release->download_url; 12 | } 13 | -------------------------------------------------------------------------------- /scripts/reverse_dependencies/by-dist-www-mech.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use JSON::MaybeXS qw( decode_json ); 8 | use WWW::Mechanize::GZip (); 9 | 10 | my $mech = WWW::Mechanize::GZip->new; 11 | 12 | $mech->get( 13 | "https://fastapi.metacpan.org/v1/reverse_dependencies/dist/Carton"); 14 | 15 | my $results = decode_json( $mech->content ); 16 | 17 | my @dists 18 | = map { $_->{distribution} } @{ $results->{data} }; 19 | p @dists; 20 | -------------------------------------------------------------------------------- /scripts/reverse_dependencies/by-module-www-mech.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Printer; 7 | use JSON::MaybeXS qw( decode_json ); 8 | use WWW::Mechanize::GZip (); 9 | 10 | my $mech = WWW::Mechanize::GZip->new; 11 | 12 | $mech->get( 13 | "https://fastapi.metacpan.org/v1/reverse_dependencies/module/WWW::Mechanize" 14 | ); 15 | 16 | my $results = decode_json( $mech->content ); 17 | 18 | my @dists 19 | = map { $_->{distribution} } @{ $results->{data} }; 20 | p @dists; 21 | -------------------------------------------------------------------------------- /scripts/search/autocomplete/www-mech.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | use feature qw( say ); 6 | 7 | use Data::Printer; 8 | use JSON::MaybeXS qw( decode_json ); 9 | use WWW::Mechanize::GZip (); 10 | 11 | my $mech = WWW::Mechanize::GZip->new; 12 | 13 | my $search_term = shift @ARGV || 'HTML::Re'; 14 | 15 | $mech->get( 16 | "https://fastapi.metacpan.org/v1/search/autocomplete?q=$search_term"); 17 | say $mech->content; 18 | 19 | my $results = decode_json( $mech->content ); 20 | 21 | my @suggestions = map { $_->{fields} } @{ $results->{hits}->{hits} }; 22 | p @suggestions; 23 | 24 | =pod 25 | 26 | =head1 DESCRIPTION 27 | 28 | /search/autocomplete is a convenience endpoint. You GET this URL, providing a 29 | query via the "q" param. The response will be returned as JSON. You will need 30 | to fetch data from this endpoint via your own UserAgent as MetaCPAN::API does 31 | not yet support it. 32 | 33 | =cut 34 | --------------------------------------------------------------------------------