« web/cgi-bin/yatt.lib/YATT/LRXML/EntityPath.pm
↑ Summary
web/cgi-bin/yatt.lib/YATT/Util/CmdLine.pm »
| 1 | # -*- mode: perl; coding: utf-8 -*- | ||||||||||||||||||
| 2 | package YATT::Fields; | ||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 12 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 12 | ▶ | use YATT::Util::Symbol; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 166 | ▶ | sub import { | ||||||||||||||||
|
Subroutine
import: called CC=12 SCAR=24.9
| |||||||||||||||||||
| 8 | 166 | require fields; | |||||||||||||||||
| 9 | 166 | my ($thispack) = shift; | |||||||||||||||||
| 10 | 166 | my ($callpack) = caller; | |||||||||||||||||
| 11 | 166 | my @public; | |||||||||||||||||
| 12 | my @setter; | ||||||||||||||||||
| 13 | 166 | my @FIELDS; | |||||||||||||||||
| 14 | 166 | foreach my $desc (@_) { | |||||||||||||||||
| 15 | 1149 | my ($slot, $default); | |||||||||||||||||
| 16 | 1149 | ▶ | if (ref $desc) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 17 | 93 | $slot = shift @$desc; | |||||||||||||||||
| 18 | 93 | $default = do { | |||||||||||||||||
| 19 | 93 | ▶ | if (@$desc > 1) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 20 | 11 | ▶ | sub { wantarray ? @$desc : [@$desc]; }; | ||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||
| 21 | } elsif (! @$desc) { | ||||||||||||||||||
| 22 | 0 | undef; | |||||||||||||||||
| 23 | } elsif (ref(my $value = $desc->[0]) eq 'CODE') { | ||||||||||||||||||
| 24 | 10 | $value; | |||||||||||||||||
| 25 | } else { | ||||||||||||||||||
| 26 | 0 | ▶ | sub () { $value; } | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 27 | 72 | } | |||||||||||||||||
| 28 | }; | ||||||||||||||||||
| 29 | } else { | ||||||||||||||||||
| 30 | 1056 | $slot = $desc; | |||||||||||||||||
| 31 | } | ||||||||||||||||||
| 32 | 1149 | ▶ | if ($slot =~ s/^([\^=]+)((?:cf_)?)//) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 33 | 222 | my $func_name = $slot; | |||||||||||||||||
| 34 | 222 | my $cf_slot = "$2$slot"; | |||||||||||||||||
| 35 | 222 | foreach my $ch (split //, $1) { | |||||||||||||||||
| 36 | 249 | ▶ | push @public, [$func_name, $cf_slot] if $ch eq '^'; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 37 | 249 | ▶ | push @setter, [$func_name, $cf_slot] if $ch eq '='; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 38 | } | ||||||||||||||||||
| 39 | 222 | push @FIELDS, $cf_slot; | |||||||||||||||||
| 40 | } else { | ||||||||||||||||||
| 41 | 927 | push @FIELDS, $slot; | |||||||||||||||||
| 42 | } | ||||||||||||||||||
| 43 | 1149 | ▶ | if (defined $default) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 44 | 93 | *{globref($callpack, "default_$slot")} = $default; | |||||||||||||||||
| 45 | } | ||||||||||||||||||
| 46 | } | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | 166 | my $script = <<END; | |||||||||||||||||
| 49 | package $callpack; | ||||||||||||||||||
| 50 | use fields qw(@FIELDS); | ||||||||||||||||||
| 51 | sub MY () {__PACKAGE__} | ||||||||||||||||||
| 52 | END | ||||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | 166 | $script .= join "", map {sprintf <<'END', @$_} @public; | |||||||||||||||||
| 55 | sub %1$s { | ||||||||||||||||||
| 56 | my MY $self = shift; | ||||||||||||||||||
| 57 | return $self->{%2$s} if defined $self->{%2$s}; | ||||||||||||||||||
| 58 | return undef unless my $sub = $self->can('default_%1$s'); | ||||||||||||||||||
| 59 | $self->{%2$s} = $sub->(); | ||||||||||||||||||
| 60 | } | ||||||||||||||||||
| 61 | END | ||||||||||||||||||
| 62 | |||||||||||||||||||
| 63 | 166 | $script .= join "", map {sprintf <<'END', @$_} @setter; | |||||||||||||||||
| 64 | sub set_%s { | ||||||||||||||||||
| 65 | my MY $self = shift; | ||||||||||||||||||
| 66 | $self->{%s} = shift; | ||||||||||||||||||
| 67 | $self; | ||||||||||||||||||
| 68 | } | ||||||||||||||||||
| 69 | END | ||||||||||||||||||
| 70 | |||||||||||||||||||
| 71 | 166 | eval qq{#line 1 "/dev/null"\n}.$script; | |||||||||||||||||
| 72 | 166 | ▶ | die "$@\n$script" if $@; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 73 | } | ||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | 12 | 1; | |||||||||||||||||