| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::perlminlint::Object; sub MY () {__PACKAGE__} | 
| 2 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 3 | 1 |  |  | 1 |  | 5 | use warnings FATAL => qw/all/; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 40 |  | 
| 4 | 1 |  |  | 1 |  | 5 | use Carp; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 82 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | require fields; | 
| 7 | 1 |  |  | 1 |  | 5 | use parent qw/File::Spec/; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our %FIELDS; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub new { | 
| 12 | 0 |  |  | 0 | 0 | 0 | my MY $self = fields::new(shift); | 
| 13 | 0 |  |  |  |  | 0 | $self->configure(@_); | 
| 14 | 0 |  |  |  |  | 0 | $self->after_new; | 
| 15 | 0 |  |  |  |  | 0 | $self; | 
| 16 |  |  |  |  |  |  | } | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  | 0 | 0 |  | sub after_new {} | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub configure { | 
| 21 | 0 |  |  | 0 | 0 | 0 | (my MY $self) = shift; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 0 | 0 | 0 |  |  | 0 | my @args = @_ == 1 && ref $_[0] eq 'HASH' ? %{$_[0]} : @_; | 
|  | 0 |  |  |  |  | 0 |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 0 |  |  |  |  | 0 | my $fields = _fields_hash($self); | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 0 |  |  |  |  | 0 | my @task; | 
| 28 | 0 |  |  |  |  | 0 | while (my ($key, $value) = splice @args, 0, 2) { | 
| 29 | 0 | 0 |  |  |  | 0 | unless (defined $key) { | 
| 30 | 0 |  |  |  |  | 0 | croak "Undefined option name for class ".ref($self); | 
| 31 |  |  |  |  |  |  | } | 
| 32 | 0 | 0 |  |  |  | 0 | next unless $key =~ m{^[A-Za-z]\w+\z}; | 
| 33 | 0 | 0 |  |  |  | 0 | unless (exists $fields->{$key}) { | 
| 34 | 0 |  |  |  |  | 0 | croak "Unknown option for class ".ref($self).": ".$key; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 0 | 0 |  |  |  | 0 | if (my $sub = $self->can("onconfigure_$key")) { | 
| 38 | 0 |  |  |  |  | 0 | push @task, [$sub, $value]; | 
| 39 |  |  |  |  |  |  | } else { | 
| 40 | 0 |  |  |  |  | 0 | $self->{$key} = $value; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 0 |  |  |  |  | 0 | $_->[0]->($self, $_->[-1]) for @task; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 0 |  |  |  |  | 0 | $self; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub import { | 
| 50 | 2 |  |  | 2 |  | 31 | $_[0]->dispatch_import(scalar caller, \@_); | 
| 51 | 2 |  |  |  |  | 13 | require Exporter; | 
| 52 | 2 |  |  |  |  | 151 | goto &Exporter::import; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub dispatch_import { | 
| 56 | 2 |  |  | 2 | 0 | 6 | my ($myPack, $callpack, $args) = @_; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | # | 
| 59 |  |  |  |  |  |  | # To allow falling back to Exporter::import, | 
| 60 |  |  |  |  |  |  | # We need to keep original $_[0] in $args. | 
| 61 |  |  |  |  |  |  | # That's why we scan $args->[1] | 
| 62 |  |  |  |  |  |  | # | 
| 63 | 2 |  | 66 |  |  | 29 | while (@$args >= 2 | 
|  |  |  | 66 |  |  |  |  | 
| 64 |  |  |  |  |  |  | and (ref $args->[1] or $args->[1] =~ /^-/)) { | 
| 65 | 2 |  |  |  |  | 24 | my $argSpec = splice @$args, 1, 1; | 
| 66 | 2 |  |  |  |  | 5 | my ($pragma, @args) = do { | 
| 67 | 2 | 100 |  |  |  | 9 | if (ref $argSpec) { | 
| 68 | 1 |  |  |  |  | 6 | @$argSpec | 
| 69 |  |  |  |  |  |  | } else { | 
| 70 | 1 | 50 |  |  |  | 10 | ($argSpec =~ s/^-// | 
| 71 |  |  |  |  |  |  | ? ($argSpec => 1) | 
| 72 |  |  |  |  |  |  | : $argSpec); | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  | }; | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 2 | 50 |  |  |  | 30 | if (my $sub = $myPack->can("declare_$pragma")) { | 
| 77 | 2 |  |  |  |  | 9 | $sub->($myPack, $callpack, @args); | 
| 78 |  |  |  |  |  |  | } else { | 
| 79 | 0 |  |  |  |  | 0 | croak "Unknown pragma '$pragma' in $callpack"; | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | sub declare_as_base { | 
| 85 | 1 |  |  | 1 | 0 | 4 | my ($myPack, $callpack, @fields) = @_; | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | # Special case. -as_base is treated as [as_base => 1]; | 
| 88 | 1 | 50 | 50 |  |  | 16 | if (@fields == 1 and ($fields[0] // '') eq 1) { | 
|  |  |  | 33 |  |  |  |  | 
| 89 | 1 |  |  |  |  | 3 | pop @fields; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 1 |  |  |  |  | 5 | $myPack->declare_fields($callpack, @fields); | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 1 |  |  |  |  | 5 | $myPack->_declare_constant_in($callpack, MY => $callpack, 1); | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | sub _declare_constant_in { | 
| 98 | 1 |  |  | 1 |  | 4 | my ($myPack, $callpack, $name, $value, $or_ignore) = @_; | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 1 |  |  |  |  | 3 | my $my_sym = _globref($callpack, $name); | 
| 101 | 1 | 50 |  |  |  | 3 | if (*{$my_sym}{CODE}) { | 
|  | 1 |  |  |  |  | 6 |  | 
| 102 | 1 | 50 |  |  |  | 16 | return if $or_ignore; | 
| 103 | 0 |  |  |  |  | 0 | croak "constant ${callpack}::$name is already defined"; | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 0 |  |  | 0 |  | 0 | *$my_sym = sub () {$value}; | 
|  | 0 |  |  |  |  | 0 |  | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | sub declare_fields { | 
| 110 | 2 |  |  | 2 | 0 | 9 | (my MY $self, my ($pack, @fields)) = @_; | 
| 111 |  |  |  |  |  |  |  | 
| 112 | 2 |  | 33 |  |  | 5 | push @{*{_globref($pack, 'ISA')}}, ref($self) || $self; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 11 |  | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 2 |  |  |  |  | 10 | my $super = _fields_hash($self); | 
| 115 | 2 |  |  |  |  | 7 | my $extended = _fields_hash($pack); | 
| 116 |  |  |  |  |  |  |  | 
| 117 | 2 |  |  |  |  | 19 | foreach my $name (keys %$super) { | 
| 118 | 0 |  |  |  |  | 0 | $extended->{$name} = $super->{$name}; # XXX: clone? | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 2 |  |  |  |  | 6 | foreach my $spec (@fields) { | 
| 122 | 4 | 50 |  |  |  | 17 | my ($name, @rest) = ref $spec ? @$spec : $spec; | 
| 123 | 4 |  |  |  |  | 12 | my $has_getter = $name =~ s/^\^//; | 
| 124 | 4 |  |  |  |  | 13 | $extended->{$name} = \@rest; # XXX: should have better object. | 
| 125 | 4 | 50 |  |  |  | 17 | if ($has_getter) { | 
| 126 | 0 |  |  | 0 |  | 0 | *{_globref($pack, $name)} = sub { $_[0]->{$name} }; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 | 2 |  |  |  |  | 12 | $pack; | 
| 131 |  |  |  |  |  |  | } | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | sub _fields_hash { | 
| 134 | 4 |  |  | 4 |  | 14 | my $sym = _fields_symbol(@_); | 
| 135 | 4 | 100 |  |  |  | 10 | unless (*{$sym}{HASH}) { | 
|  | 4 |  |  |  |  | 18 |  | 
| 136 | 1 |  |  |  |  | 4 | *$sym = {}; | 
| 137 |  |  |  |  |  |  | } | 
| 138 | 4 |  |  |  |  | 8 | *{$sym}{HASH}; | 
|  | 4 |  |  |  |  | 13 |  | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | sub _fields_symbol { | 
| 142 | 4 |  |  | 4 |  | 13 | _globref($_[0], 'FIELDS'); | 
| 143 |  |  |  |  |  |  | } | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | sub _globref { | 
| 146 | 7 |  |  | 7 |  | 18 | my ($thing, $name) = @_; | 
| 147 | 7 |  | 33 |  |  | 42 | my $class = ref $thing || $thing; | 
| 148 | 1 |  |  | 1 |  | 1257 | no strict 'refs'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 66 |  | 
| 149 | 7 | 50 |  |  |  | 12 | \*{join("::", $class, defined $name ? $name : ())}; | 
|  | 7 |  |  |  |  | 90 |  | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | 1; | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | __END__ |