| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 2 |  |  | 2 |  | 14 | use warnings; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 97 |  | 
| 2 | 2 |  |  | 2 |  | 14 | use strict; | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 146 |  | 
| 3 |  |  |  |  |  |  | package Net::OAuth2::Scheme::Option::Defines; | 
| 4 |  |  |  |  |  |  | BEGIN { | 
| 5 | 2 |  |  | 2 |  | 245 | $Net::OAuth2::Scheme::Option::Defines::VERSION = '0.03'; | 
| 6 |  |  |  |  |  |  | } | 
| 7 |  |  |  |  |  |  | # ABSTRACT: functions for creating option groups and default values | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our (@ISA, @EXPORT, @EXPORT_OK); | 
| 10 |  |  |  |  |  |  | BEGIN { | 
| 11 | 2 |  |  | 2 |  | 9 | @EXPORT = qw(Default_Value Define_Group); | 
| 12 | 2 |  |  |  |  | 228 | @EXPORT_OK = qw(All_Classes); | 
| 13 |  |  |  |  |  |  | } | 
| 14 | 2 |  |  | 2 |  | 17 | use parent qw(Exporter); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 25 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | my $_marker; # value does not matter | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | # _mark(CLASS) | 
| 19 |  |  |  |  |  |  | # marks the class as containing stuff that we care about | 
| 20 |  |  |  |  |  |  | sub _mark { | 
| 21 | 3 |  |  | 3 |  | 4 | my $class = shift; | 
| 22 | 2 |  |  | 2 |  | 243 | no strict 'refs'; | 
|  | 2 |  |  |  |  | 16 |  | 
|  | 2 |  |  |  |  | 238 |  | 
| 23 | 3 |  |  |  |  | 7 | ${"${class}::_Has_Defaults_Or_Groups"} = \ $_marker; | 
|  | 3 |  |  |  |  | 18 |  | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | # _is_marked(CLASS) | 
| 27 |  |  |  |  |  |  | # does this class contain stuff that we care about | 
| 28 |  |  |  |  |  |  | sub _is_marked { | 
| 29 | 14 |  |  | 14 |  | 20 | my $class = shift; | 
| 30 | 2 |  |  | 2 |  | 11 | no strict 'refs'; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 77 |  | 
| 31 | 2 |  |  | 2 |  | 10 | no warnings 'uninitialized'; | 
|  | 2 |  |  |  |  | 11 |  | 
|  | 2 |  |  |  |  | 198 |  | 
| 32 | 14 |  |  |  |  | 18 | return ${"${class}::_Has_Defaults_Or_Groups"} == \ $_marker; | 
|  | 14 |  |  |  |  | 100 |  | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # All_Classes(CLASS) | 
| 36 |  |  |  |  |  |  | # return all classes in the ancestor tree of CLASS | 
| 37 |  |  |  |  |  |  | # that contain stuff that we care about | 
| 38 |  |  |  |  |  |  | sub All_Classes { | 
| 39 | 14 |  |  | 14 | 1 | 19 | my $class = shift; | 
| 40 | 2 |  |  | 2 |  | 31 | no strict 'refs'; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 242 |  | 
| 41 |  |  |  |  |  |  | return | 
| 42 | 14 | 100 |  |  |  | 17 | ((map { All_Classes($_) } @{"${class}::ISA"}), | 
|  | 7 |  |  |  |  | 18 |  | 
|  | 14 |  |  |  |  | 53 |  | 
| 43 |  |  |  |  |  |  | (_is_marked($class) ? ($class) : ())); | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub Default_Value { | 
| 47 | 1 |  |  | 1 | 1 | 7 | my ($oname, $value) = @_; | 
| 48 | 1 |  |  |  |  | 5 | my $class = caller; | 
| 49 | 1 |  |  |  |  | 15 | _mark($class); | 
| 50 | 2 |  |  | 2 |  | 9 | no strict 'refs'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 263 |  | 
| 51 | 1 |  |  |  |  | 2 | ${"${class}::Default"}{$oname} = $value; | 
|  | 1 |  |  |  |  | 8 |  | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # suppress warning about Default only being used once | 
| 54 | 1 |  |  |  |  | 2 | ${"${class}::Default"}{''} = 0; | 
|  | 1 |  |  |  |  | 5 |  | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub Define_Group { | 
| 58 | 2 |  |  | 2 | 1 | 12 | my ($gname, $default, @keys) = @_; | 
| 59 | 2 |  |  |  |  | 9 | my $class = caller; | 
| 60 | 2 |  |  |  |  | 25 | _mark($class); | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | # if no keys given, assume single-option group | 
| 63 |  |  |  |  |  |  | # with option name as the group name | 
| 64 | 2 | 100 |  |  |  | 8 | @keys = ($gname) unless @keys; | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 2 |  |  | 2 |  | 11 | no strict 'refs'; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 418 |  | 
| 67 | 2 | 100 |  |  |  | 16 | ${"${class}::Group"}{$gname} = | 
|  | 2 |  |  |  |  | 12 |  | 
| 68 |  |  |  |  |  |  | +{ | 
| 69 |  |  |  |  |  |  | keys => \@keys, | 
| 70 |  |  |  |  |  |  | (defined($default) | 
| 71 |  |  |  |  |  |  | ? (default => ["pkg_${gname}_${default}"]) | 
| 72 |  |  |  |  |  |  | : ()), | 
| 73 |  |  |  |  |  |  | }; | 
| 74 |  |  |  |  |  |  | # suppress warning about Group only being used once | 
| 75 | 2 |  |  |  |  | 7 | ${"${class}::Group"}{''} = +{ keys => [] }; | 
|  | 2 |  |  |  |  | 10 |  | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | 1; | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | __END__ |