| 1 | package Kwiki::Preferences; | ||||||||||||
| 2 | 1 | ▶ | use Kwiki::Base -Base; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | ▶ | |||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | field class_id => 'preferences'; | |||||||||||
| 5 | 1 | const preference_class => 'Kwiki::Preference'; | |||||||||||
| 6 | 1 | field objects_by_class => {}; | |||||||||||
| 7 | |||||||||||||
| 8 | 0 | ▶ | sub load { | ||||||||||
|
Subroutine
load: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 9 | 0 | my $values = shift; | |||||||||||
| 10 | 0 | my $prefs = $self->hub->registry->lookup->preference; | |||||||||||
| 11 | 0 | for (sort keys %$prefs) { | |||||||||||
| 12 | 0 | my $array = $prefs->{$_}; | |||||||||||
| 13 | 0 | my $class_id = $array->[0]; | |||||||||||
| 14 | 0 | ▶ | my $hash = {@{$array}[1..$#{$array}]} | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 15 | or next; | ||||||||||||
| 16 | 0 | ▶ | next unless $hash->{object}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 17 | 0 | my $object = $hash->{object}->clone; | |||||||||||
| 18 | 0 | $object->value($values->{$_}); | |||||||||||
| 19 | 0 | push @{$self->objects_by_class->{$class_id}}, $object; | |||||||||||
| 20 | 0 | field($_); | |||||||||||
| 21 | 0 | $self->$_($object); | |||||||||||
| 22 | } | ||||||||||||
| 23 | 0 | return $self; | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | 0 | ▶ | sub new_preferences { | ||||||||||
|
Subroutine
new_preferences: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 27 | 0 | my $values = shift; | |||||||||||
| 28 | 0 | my $new = bless {}, ref $self; | |||||||||||
| 29 | 0 | $new->load($values); | |||||||||||
| 30 | 0 | return $new; | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 0 | ▶ | sub new_preference { | ||||||||||
|
Subroutine
new_preference: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 34 | 0 | $self->preference_class->new(@_); | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | #------------------------------------------------------------------------------# | ||||||||||||
| 38 | package Kwiki::Preference; | ||||||||||||
| 39 | 1 | ▶ | use Kwiki::Base '-base'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 40 | |||||||||||||
| 41 | 1 | field 'id'; | |||||||||||
| 42 | 1 | field 'name'; | |||||||||||
| 43 | 1 | field 'description'; | |||||||||||
| 44 | 1 | field 'query'; | |||||||||||
| 45 | 1 | field 'type'; | |||||||||||
| 46 | 1 | field 'choices'; | |||||||||||
| 47 | 1 | field 'default'; | |||||||||||
| 48 | 1 | field 'handler'; | |||||||||||
| 49 | 1 | field 'owner_id'; | |||||||||||
| 50 | 1 | field 'size' => 20; | |||||||||||
| 51 | 1 | field 'edit'; | |||||||||||
| 52 | 1 | field 'new_value'; | |||||||||||
| 53 | 1 | field 'error'; | |||||||||||
| 54 | |||||||||||||
| 55 | 0 | ▶ | sub new() { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||
| 56 | 0 | my $class = shift; | |||||||||||
| 57 | 0 | my $owner = shift; | |||||||||||
| 58 | 0 | my $self = bless {}, $class; | |||||||||||
| 59 | 0 | ▶ | my $id = shift || ''; | ||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 60 | 0 | $self->id($id); | |||||||||||
| 61 | 0 | my $name = $id; | |||||||||||
| 62 | 0 | $name =~ s/_/ /g; | |||||||||||
| 63 | 0 | $name =~ s/\b(.)/\u$1/g; | |||||||||||
| 64 | 0 | $self->name($name); | |||||||||||
| 65 | 0 | $self->query("$name?"); | |||||||||||
| 66 | 0 | $self->type('boolean'); | |||||||||||
| 67 | 0 | $self->default(0); | |||||||||||
| 68 | 0 | $self->handler("${id}_handler"); | |||||||||||
| 69 | 0 | $self->owner_id($owner->class_id); | |||||||||||
| 70 | 0 | return $self; | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | 0 | ▶ | sub value { | ||||||||||
|
Subroutine
value: not called CC=3 SCAR=24.8
| |||||||||||||
| 74 | return $self->{value} = shift | ||||||||||||
| 75 | 0 | ▶ | if @_; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | return defined $self->{value} | ||||||||||||
| 77 | ? $self->{value} | ||||||||||||
| 78 | 0 | ▶ | : $self->default; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | 0 | ▶ | sub value_label { | ||||||||||
|
Subroutine
value_label: not called CC=3 SCAR=24.8
| |||||||||||||
| 82 | 0 | ▶ | my $choices = $self->choices | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | or return ''; | ||||||||||||
| 84 | 0 | ▶ | return ${{@$choices}}{$self->value} || ''; | ||||||||||
|
Condition0%0/2
${+{@$choices};}{$self->value} || ''
MC/DC0%0/1
${+{@$choices};}{$self->value} || ''
${+{@$choices};}{$self->value}
Truth table0%0/2
A
A= ${+{@$choices};}{$self->value}
| |||||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | 0 | ▶ | sub form_element { | ||||||||||
|
Subroutine
form_element: not called CC=1 SCAR=6.9
| |||||||||||||
| 88 | 0 | my $type = $self->type; | |||||||||||
| 89 | 0 | return $self->$type; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 0 | ▶ | sub input { | ||||||||||
|
Subroutine
input: not called CC=1 SCAR=6.9
| |||||||||||||
| 93 | 0 | my $name = $self->owner_id . '__' . $self->id; | |||||||||||
| 94 | 0 | my $value = $self->value; | |||||||||||
| 95 | 0 | my $size = $self->size; | |||||||||||
| 96 | return <<END | ||||||||||||
| 97 | <input type="text" name="$name" value="$value" size="$size" /> | ||||||||||||
| 98 | END | ||||||||||||
| 99 | 0 | } | |||||||||||
| 100 | |||||||||||||
| 101 | 0 | ▶ | sub boolean { | ||||||||||
|
Subroutine
boolean: not called CC=2 SCAR=17.9
| |||||||||||||
| 102 | 0 | my $name = $self->owner_id . '__' . $self->id; | |||||||||||
| 103 | 0 | my $value = $self->value; | |||||||||||
| 104 | 0 | ▶ | my $checked = $value ? 'checked="checked"' : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | return <<END | ||||||||||||
| 106 | <input type="checkbox" name="$name" value="1" $checked /> | ||||||||||||
| 107 | <input type="hidden" name="$name-boolean" value="0" $checked /> | ||||||||||||
| 108 | END | ||||||||||||
| 109 | 0 | } | |||||||||||
| 110 | |||||||||||||
| 111 | 0 | ▶ | sub radio { | ||||||||||
|
Subroutine
radio: not called CC=1 SCAR=6.9
| |||||||||||||
| 112 | 0 | my $i = 1; | |||||||||||
| 113 | 0 | my @choices = @{$self->choices}; | |||||||||||
| 114 | 0 | my @values = grep {$i++ % 2} @choices; | |||||||||||
| 115 | 0 | my $value = $self->value; | |||||||||||
| 116 | |||||||||||||
| 117 | 0 | join "\n", | |||||||||||
| 118 | '<table bgcolor="#e0e0e0"><tr><td align="left">', | ||||||||||||
| 119 | CGI::radio_group( | ||||||||||||
| 120 | -name => $self->owner_id . '__' . $self->id, | ||||||||||||
| 121 | -values => \@values, | ||||||||||||
| 122 | -default => $value, | ||||||||||||
| 123 | -labels => { @choices }, | ||||||||||||
| 124 | -override => 1, | ||||||||||||
| 125 | -linebreak=>'true', | ||||||||||||
| 126 | ), | ||||||||||||
| 127 | '</td></tr></table>'; | ||||||||||||
| 128 | } | ||||||||||||
| 129 | |||||||||||||
| 130 | 0 | ▶ | sub pulldown { | ||||||||||
|
Subroutine
pulldown: not called CC=1 SCAR=6.9
| |||||||||||||
| 131 | 0 | my $i = 1; | |||||||||||
| 132 | 0 | my @choices = @{$self->choices}; | |||||||||||
| 133 | 0 | my @values = grep {$i++ % 2} @choices; | |||||||||||
| 134 | 0 | my $value = $self->value; | |||||||||||
| 135 | 0 | CGI::popup_menu( | |||||||||||
| 136 | -name => $self->owner_id . '__' . $self->id, | ||||||||||||
| 137 | -values => \@values, | ||||||||||||
| 138 | -default => $value, | ||||||||||||
| 139 | -labels => { @choices }, | ||||||||||||
| 140 | -override => 1, | ||||||||||||
| 141 | ); | ||||||||||||
| 142 | } | ||||||||||||
| 143 | |||||||||||||
| 144 | 1 | __DATA__ | |||||||||||