MARC/Leader.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 59 CC 3 SCAR 16.1
CC
3
Cov
0%
Populate
12.0
ClassInit
2.0
get
2.0
CRAP 5.0
1 $Tk::MARC::Leader::VERSION = '0.3';
2
3 package Tk::MARC::Leader;
4
5 =head1 NAME
6
7 Tk::MARC::Leader - megawidget for editing MARC::Record leader.
8
9 =head1 SYNOPSIS
10
11 use Tk;
12 use Tk::MARC::Leader;
13 use MARC::Record;
14 use MARC::File::USMARC;
15
16 my $file = MARC::File::USMARC->in( "pl/tcfm.mrc" );
17 my $record = $file->next();
18 $file->close();
19 undef $file;
20
21 my $mw = MainWindow->new;
22 $mw->title("leader Test");
23 $mw->MARC_Leader(-record => $record)->pack;
24
25 MainLoop;
26
27 =head1 DESCRIPTION
28
29 This is a megawidget that allows editing of a MARC::Record leader.
30 The widget itself does not change the MARC::Record leader - that is
31 up to the widget's parent.
32
33 WARNING: As with the MARC::Record->leader() function (on which this
34 is based), NO ERROR CHECKING IS DONE on the leader. This widget
35 basically exists so that, in future, it will be easy to add leader
36 error checking....
37
38 You will likely never use a Tk::MARC::Leader directly - it is simply
39 a component of Tk::MARC::record.
40
41 =cut
42
43 # Revision history for Tk::MARC::Leader.
44 # --------------------------------------
45 # 0.3 January 20, 2004
46 # - croak on missing -record
47 #
48 # 0.2 January 17, 2004
49 # - renamed to Tk::MARC::Leader (capitalized 'Leader')
50 # to be consistant with Tk::MARC::Field
51 #
52 # 0.1 January 16, 2004
53 # - original version
54
55 use Tk::widgets;
56 use base qw/Tk::Frame/;
57 use MARC::Descriptions;
58 use Carp;
59 use strict;
60
61 Construct Tk::Widget 'MARC_Leader';
62
63 our (
64 $TD, # MARC::Descriptions tag data
65 );
66
67 sub ClassInit {
68 my ($class, $mw) = @_;
69 $TD = new MARC::Descriptions;
70 $class->SUPER::ClassInit($mw);
71 }
72
73 sub Populate {
74 my ($self, $args) = @_;
75
76 my $record = delete $args->{'-record'};
77 $self->SUPER::Populate($args);
78 $self->{"fixed_font"} = "-adobe-courier-medium-r-normal--14-100-75-75-m-60-iso8859-2";
79
80 croak "Missing -record" unless defined($record);
81 croak "Not a MARC::Record" unless (ref($record) eq "MARC::Record");
82 $self->{VALUE} = $record->leader();
83 $self->{ORIGINAL_VALUE} = $self->{VALUE};
84
85 my $FRAME = $self->Frame()->pack(-side => 'top',
86 -expand => 1,
87 -anchor => 'nw',
88 -fill => 'x');
89
90 my $LABEL = $FRAME->Label(-text => 'LEADER',
91 -font => $self->{"fixed_font"}
92 )->pack(-side => 'left',
93 -fill => 'x');
94 my $ENTRY = $FRAME->Entry(-textvariable => \$self->{VALUE},
95 -width => 24,
96 -background => "gray",
97 )->pack(-side => 'left',
98 -expand => 0,
99 -fill => 'x');
100
101 $ENTRY->bind("<KeyPress>", sub { $ENTRY->configure(-background => "green");
102 });
103 my $B_ORIG = $FRAME->Button(-text => "O",
104 -font => $self->{"fixed_font"},
105 -width => 1,
106 -height => 1,
107 -padx => 0,
108 -pady => 0,
109 -command => sub {
110 $self->{VALUE} = $self->{ORIGINAL_VALUE};
111 $ENTRY->configure(-background => "gray");
112 }
113 )->pack(-side => 'left');
114
115 $self->Advertise( 'leader', $ENTRY );
116 $self->ConfigSpecs( '-record' => [ 'PASSIVE', undef, undef, undef],
117 'DEFAULT' => [$FRAME],
118 );
119 $self->Delegates( 'DEFAULT' => $FRAME );
120 }
121
122 sub get {
123 my $self = shift;
124
125 return $self->{VALUE};
126 }
127
128 =head1 AUTHOR
129
130 David Christensen, <DChristensenSPAMLESS@westman.wave.ca>
131
132 =cut
133
134 =head1 COPYRIGHT AND LICENSE
135
136 Copyright 2004 by David Christensen
137
138 This library is free software; you can redistribute it and/or modify it
139 under the same terms as Perl itself.
140
141 =cut
142
143 1;