License.pm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # $OpenBSD: License.pm,v 1.2 2016/04/27 09:58:35 tsg Exp $
  2. #
  3. # Copyright (c) 2015 Giannis Tsaraias <tsg@openbsd.org>
  4. #
  5. # Permission to use, copy, modify, and distribute this software for any
  6. # purpose with or without fee is hereby granted, provided that the above
  7. # copyright notice and this permission notice appear in all copies.
  8. #
  9. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. package OpenBSD::PortGen::License;
  17. use 5.012;
  18. use warnings;
  19. use parent qw( Exporter );
  20. our @EXPORT_OK = qw(
  21. is_good
  22. pretty_license
  23. );
  24. # Add licenses not recognized here.
  25. my %good_licenses = (
  26. agpl_3 => 'AGPL 3',
  27. apache_1_1 => 'Apache 1.1',
  28. apache_2_0 => 'Apache 2.0',
  29. artistic_1 => 'Artistic 1.0',
  30. artistic_2 => 'Artistic 2.0',
  31. bsd => 'BSD',
  32. freebsd => 'FreeBSD',
  33. gpl_2 => 'GPLv2',
  34. gpl_2_0 => 'GPLv2',
  35. gpl_3 => 'GPLv3',
  36. lgpl => 'LGPL',
  37. lgpl_2_1 => 'LGPL v2.1',
  38. 'lgpl_2_1+' => 'LGPL v2.1',
  39. mit => 'MIT',
  40. new_bsd => 'BSD-3',
  41. perl_5 => 'Perl',
  42. ruby => 'Ruby',
  43. qpl_1_0 => 'QPLv1',
  44. zlib => 'zlib',
  45. );
  46. sub is_good
  47. {
  48. my $license = shift;
  49. return unless $license;
  50. return defined $good_licenses{ _munge($license) };
  51. }
  52. sub pretty_license
  53. {
  54. my $raw = shift;
  55. return "license field not set, consider bugging module's author"
  56. if !$raw or $raw eq 'UNKNOWN';
  57. return $good_licenses{ _munge($raw) } || "unknown license -> '$raw'";
  58. }
  59. sub _munge
  60. {
  61. my $license = shift;
  62. $license = lc $license;
  63. $license =~ s/[,-\.\s]/_/g;
  64. $license =~ s/_license//;
  65. $license =~ s/_version//;
  66. $license =~ s/_{2,}/_/g;
  67. return $license;
  68. }
  69. 1;