File Coverage

lib/Devel/ebug/Wx/Command/State.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Devel::ebug::Wx::Command::State;
2              
3 1     1   1453 use strict;
  1         2  
  1         32  
4              
5 1     1   390 use Wx qw(:filedialog);
  0            
  0            
6             use File::Basename qw(basename dirname);
7              
8             sub register_commands {
9             return
10             ( save_state => { sub => \&save_program_state,
11             menu => 'file',
12             label => 'Save state',
13             priority => 100,
14             },
15             load_state => { sub => \&load_program_state,
16             menu => 'file',
17             label => 'Load state',
18             priority => 100,
19             },
20             );
21             }
22              
23             my $FILE;
24             my $wildcards = join '|', ( 'ebug_wx state files (*.ebug_wx)' => '*.ebug_wx',
25             'All files' => '*.*',
26             );
27              
28             sub _get_file {
29             my( $wx, $action ) = @_;
30              
31             my $flags = $action eq 'load' ? wxFD_OPEN|wxFD_FILE_MUST_EXIST :
32             wxFD_SAVE;
33             $flags ||= wxFD_CHANGE_DIR;
34             if( !$FILE ) {
35             my $script = $wx->ebug->script;
36             my( $volume, $dir, $file ) = File::Spec->splitpath( $script );
37             $file =~ s/\.\w+$/.ebug_wx/;
38             $FILE = File::Spec->catpath( $volume, $dir, $file );
39             }
40             my( $dirname, $filename ) = ( dirname( $FILE ), basename( $FILE ) );
41             my $new_file = Wx::FileSelector( "Choose a saved profile", $dirname,
42             $filename, "ebug_wx", $wildcards,
43             $flags, $wx );
44             $FILE = $new_file if $new_file;
45             return $new_file ? 1 : 0;
46             }
47              
48             sub load_program_state {
49             my( $wx ) = @_;
50              
51             return unless _get_file( $wx );
52             $wx->service_manager->maybe_call_method( 'load_program_state', $FILE );
53             }
54              
55             sub save_program_state {
56             my( $wx ) = @_;
57              
58             return unless _get_file( $wx );
59             $wx->service_manager->maybe_call_method( 'save_program_state', $FILE );
60             $wx->configuration_service->flush( $FILE );
61             }
62              
63             1;