Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

cpanfileがRubyでパースできることに気づいた俺たちは

4,838 views

Published on

2018-09-08 builderscon tokyo 2018 LT

Published in: Technology
  • Be the first to comment

cpanfileがRubyでパースできることに気づいた俺たちは

  1. 1. 

  2. 2. requires 'Plack'; ... on test => sub { requires 'Test2', '1.302138'; ... }
  3. 3. $ ruby -cw cpanfile Syntax OK
  4. 4. # requires CPAN Module requires 'Plack'; ... # env on <ENV> sub on test => sub { # 2 requires 'Test2', '1.302138'; ... }
  5. 5. requires 'Plack';
  6. 6. on test => sub { requires 'Test2', '1.302138'; }
  7. 7. on({ test => sub { requires 'Test2', '1.302138'; } })
  8. 8. on({ test => sub { requires 'Test2', '1.302138'; } })
  9. 9. on({ test => sub { requires 'Test2', '1.302138'; } })
  10. 10. on({ test => sub { requires 'Test2', '1.302138'; } })
  11. 11. on({ test => sub { requires 'Test2', '1.302138'; } })
  12. 12. on({ test => sub { requires 'Test2', '1.302138'; } })
  13. 13. requires ‘Plack'; requires 'Test2', '1.302138';
  14. 14. @requires = [] def requires(module_name, version = nil) @requires << [module_name, version] end
  15. 15. on({ test => sub { requires 'Test2', '1.302138'; } })
  16. 16. def on(_hash) # nop end
  17. 17. on({ test => sub { requires 'Test2', '1.302138'; } })
  18. 18. def test "test" end
  19. 19. on({ test => sub { requires 'Test2', '1.302138'; } })
  20. 20. def sub yield end
  21. 21. def sub -> { yield } end def on(hash) hash.each do |env, sub| sub.call end end
  22. 22. eval File.read("./cpanfile") pp @requires
  23. 23. $ ruby cpanfile_parser.rb [["Plack", nil], ["Test2", "1.302138"]]

×