ObjEditorDialog.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 61 CC 3 SCAR 12.8
CC
3
Cov
0%
Populate
6.0
Show
6.0
BEGIN
2.0
CRAP 3.6
1 #
2 # This file is part of Tk-ObjEditor
3 #
4 # This software is copyright (c) 2014 by Dominique Dumont.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 package Tk::ObjEditorDialog;
10 $Tk::ObjEditorDialog::VERSION = '2.010';
11 use strict;
12 use warnings;
13  
14 use Carp;
15 use Tk::ObjEditor;
16  
17 use vars qw/$VERSION @ISA/;
18  
19 #use Storable qw(dclone);
20  
21 use base qw(Tk::Derived Tk::DialogBox);
22  
23 Tk::Widget->Construct('ObjEditorDialog');
24  
25 sub Populate {
26 my ( $cw, $args ) = @_;
27  
28 my $data = delete $args->{'caller'} || delete $args->{'-caller'};
29 $cw->{direct} = delete $args->{'direct'} || delete $args->{'-direct'} || 0;
30  
31 # need to add different button for clone ????
32 my $buttons = $cw->{direct} ? ['done'] : [qw/OK cancel/];
33  
34 $args->{-buttons} = $buttons;
35  
36 $cw->SUPER::Populate($args);
37  
38 $cw->add( 'ObjEditor', caller => $data, -direct => $cw->{direct} )->pack;
39  
40 return $cw;
41 }
42  
43 sub Show {
44 my $cw = shift;
45  
46 my $hit = $cw->SUPER::Show(@_);
47  
48 if ( $hit eq 'OK' ) {
49  
50 # no direct edit
51 return $cw->Subwidget("objeditor")->get_data();
52 }
53 else {
54 return $cw->Subwidget("objeditor")->get_orig_data();
55 }
56 }
57  
58 =head1 NAME
59  
60 Tk::ObjEditorDialog - Tk composite widget obj editor popup dialog
61  
62 =head1 SYNOPSIS
63  
64 use Tk::ObjEditorDialog;
65
66 my $editor = $mw->ObjEditorDialog( caller => $object,
67 direct => [1|0],
68 [title=>"windows"]) ;
69  
70 $editor -> Show;
71  
72 =head1 DESCRIPTION
73  
74 This widget is a L<ObjEditor> within a L<DialogBox> widget. I.e. it
75 will appear in its own toplevel window when you invoke the Show()
76 method like the FileDialog widget.
77  
78 =head1 Constructor parameters
79  
80 =over 4
81  
82 =item *
83  
84 caller: The ref of the object or hash or array to edit (mandatory).
85  
86 =item *
87  
88 title: the title of the menu created by the editor (optional)
89  
90 =item *
91  
92 direct: Set to 1 if you want to perform direct edition.
93  
94 =back
95  
96 =head1 Method
97  
98 =head2 Show(grab)
99  
100 As in L<Tk::DialogBox>, this method displays the dialog box, until
101 user invokes one of the buttons in the bottom frame. If the grab type
102 is specified in grab, then Show uses that grab; otherwise it uses a
103 local grab. Returns the name of the button invoked.
104  
105 =head1 CAVEATS
106  
107 Like L<Tk::ObjScanner> ObjEditor does not detect recursive data
108 structures. It will just keep on displaying the tree until the user
109 gets tired of clicking on the HList items.
110  
111 =head1 AUTHOR
112  
113 Dominique Dumont.
114  
115 Copyright (c) 2001 Dominique Dumont. All
116 rights reserved. This program is free software; you can redistribute
117 it and/or modify it under the same terms as Perl itself.
118  
119 =head1 SEE ALSO
120  
121 perl(1), L<Tk>, L<Tk::HList>, L<Tk::ObjScanner>, L<Tk::ObjEditor>,
122 L<Tk::DialogBox>
123  
124 =cut
125