MARC/Indicators.pm untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 107 CC 12 SCAR 35.4
CC
12
Cov
0%
Populate
56.0
get
42.0
ClassInit
2.0
CRAP 34.5
1 $Tk::MARC::Indicators::VERSION = '0.4';
2
3 package Tk::MARC::Indicators;
4
5 =head1 NAME
6
7 Tk::MARC::Indicators - megawidget for editing MARC::Field indicators.
8
9 =head1 SYNOPSIS
10
11 use Tk;
12 use Tk::MARC::Indicators;
13
14 my $mw = MainWindow->new;
15 $mw->MARC_Indicators(-field => '245',
16 -ind1 => '0',
17 -ind2 => '7',
18 )->pack(-anchor => 'w');
19 MainLoop;
20
21 =head1 DESCRIPTION
22
23 This is a megawidget that allows editing of MARC::Field indicators.
24 The widget itself does not change the MARC::Field indicators - that is
25 up to the widget's parent.
26
27 The widget provides a menu of valid indicator values (and their
28 descriptions) for the given MARC field and indicator (1 or 2).
29
30 You will likely never use a Tk::MARC::Indicators directly - it is simply
31 a component of Tk::MARC::field.
32
33 =cut
34
35 # Revision history for Tk::MARC::Indicators.
36 # ------------------------------------------
37 # 0.4 January 20, 2004
38 # - croak on missing -field
39 #
40 # 0.3 January 17, 2004
41 # - renamed to Tk::MARC::Indicators (capitalized 'Indicators')
42 # to be consistant with Tk::MARC::Field
43 #
44 # 0.2 January 15, 2004
45 # - added get() routine
46 #
47 # 0.1 January 15, 2004
48 # - original version
49
50 use Tk::widgets;
51 use base qw/Tk::Frame/;
52 use MARC::Descriptions;
53 use Carp;
54 use strict;
55
56 Construct Tk::Widget 'MARC_Indicators';
57
58 our (
59 $TD, # MARC::Descriptions tag data
60 );
61
62 sub ClassInit {
63 my ($class, $mw) = @_;
64 $TD = new MARC::Descriptions;
65 $class->SUPER::ClassInit($mw);
66 }
67
68 sub Populate {
69 my ($self, $args) = @_;
70
71 my $field = delete $args->{'-field'};
72 croak "Missing -field" unless (defined $field);
73 my $ind1 = delete $args->{'-ind1'};
74 $ind1 = ' ' unless (defined $ind1);
75 my $ind2 = delete $args->{'-ind2'};
76 $ind2 = ' ' unless (defined $ind2);
77
78 $self->SUPER::Populate($args);
79 $self->{"fixed_font"} = "-adobe-courier-medium-r-normal--14-100-75-75-m-60-iso8859-2";
80
81 my $FRAME = $self->Frame()->pack(-side => 'top',
82 -expand => 1,
83 -anchor => 'nw',
84 -fill => 'x');
85
86 if ($field ge '010') {
87 my $FRAME_IND1 = $FRAME->Frame()->pack(-side => 'top',
88 -expand => 0,
89 -fill => 'x');
90 my $IND1_LABEL = $FRAME_IND1->Label(-text => ' Ind1')->pack(-side => 'left',
91 -fill => 'x');
92 if (defined $ind1) {
93 $self->{IND1_ENTRY} = $FRAME_IND1->Entry(-textvariable => \$ind1,
94 -width => 1,
95 -background => "yellow",
96 )->pack(-side => 'left',
97 -expand => 0,
98 -fill => 'none');
99 }
100 my @menu_ind1 = ();
101 my $ind1_href = $TD->get( $field, "ind1");
102 foreach my $key (sort keys %$ind1_href) {
103 #print $ind1_href->{"$key"}->{description} . $/;
104 push @menu_ind1, ['command' => "$key $ind1_href->{$key}->{description}",
105 -command => sub { $ind1 = "$key" } ];
106 }
107 $FRAME_IND1->Menubutton(-text => "",
108 -font => $self->{"fixed_font"},
109 -width => 1,
110 -height => 1,
111 -padx => 0,
112 -pady => 0,
113 -tearoff => 0,
114 -indicatoron => 1,
115 -menuitems => \@menu_ind1,
116 )->pack(-side => 'left');
117
118 #
119 # Indicator 2
120 #
121 my $FRAME_IND2 = $FRAME->Frame()->pack(-side => 'top',
122 -expand => 0,
123 -fill => 'x');
124 my $IND2_LABEL = $FRAME_IND2->Label(-text => ' Ind2')->pack(-side => 'left',
125 -fill => 'x');
126 if (defined $ind2) {
127 $self->{IND2_ENTRY} = $FRAME_IND2->Entry(-textvariable => \$ind2,
128 -width => 1,
129 -background => "yellow",
130 )->pack(-side => 'left',
131 -expand => 0,
132 -fill => 'none');
133 }
134 my @menu_ind2 = ();
135 my $ind2_href = $TD->get( $field, "ind2");
136 foreach my $key (sort keys %$ind2_href) {
137 #print $ind1_href->{"$key"}->{description} . $/;
138 push @menu_ind2, ['command' => "$key $ind2_href->{$key}->{description}",
139 -command => sub { $ind2 = "$key" } ];
140 }
141 $FRAME_IND2->Menubutton(-text => "",
142 -font => $self->{"fixed_font"},
143 -width => 1,
144 -height => 1,
145 -padx => 0,
146 -pady => 0,
147 -tearoff => 0,
148 -indicatoron => 1,
149 -menuitems => \@menu_ind2,
150 )->pack(-side => 'left');
151
152 }
153
154 $self->Advertise( 'ind1', $self->{IND1_ENTRY} );
155 $self->Advertise( 'ind2', $self->{IND2_ENTRY} );
156 $self->ConfigSpecs( '-field' => [ 'PASSIVE', , ,'245'],
157 '-ind1' => [ 'PASSIVE', , ,' '],
158 '-ind2' => [ 'PASSIVE', , ,' '],
159 'DEFAULT' => [$FRAME],
160 );
161 $self->Delegates( 'DEFAULT' => $FRAME );
162 }
163
164 sub get {
165 my $self = shift;
166 my $ind = shift;
167
168 if (defined $ind) {
169 if ($ind == 1) {
170 if (defined $self->{IND1_ENTRY}) {
171 return $self->{IND1_ENTRY}->get();
172 } else {
173 return undef;
174 }
175 } elsif ($ind == 2) {
176 if (defined $self->{IND2_ENTRY}) {
177 return $self->{IND2_ENTRY}->get();
178 } else {
179 return undef;
180 }
181 } else {
182 croak "Tk::MARC::Indicators->get - invalid indicator #";
183 }
184 } else {
185 croak "Tk::MARC::Indicators->get - must specify an indicator #";
186 }
187 }
188
189 =head1 AUTHOR
190
191 David Christensen, <DChristensenSPAMLESS@westman.wave.ca>
192
193 =cut
194
195 =head1 COPYRIGHT AND LICENSE
196
197 Copyright 2004 by David Christensen
198
199 This library is free software; you can redistribute it and/or modify it
200 under the same terms as Perl itself.
201
202 =cut
203
204 1;