Changeset 334 for LATMOS-Accounts/lib/LATMOS
- Timestamp:
- 08/13/09 17:47:26 (15 years ago)
- Location:
- LATMOS-Accounts/lib/LATMOS/Accounts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm
r333 r334 396 396 } 397 397 } 398 return 1; 398 399 } 399 400 -
LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm
r267 r334 7 7 use utf8; 8 8 use LATMOS::Accounts::Log; 9 use File::Temp qw(tempfile); 9 10 10 11 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; … … 52 53 } 53 54 55 sub parse_obj_file { 56 my ($handle) = @_; 54 57 58 my %attributes; 59 while (my $line = <$handle>) { 60 $line =~ /^#/ and next; 61 chomp($line); 62 my ($attr, $value) = $line =~ /^\s*(\S+):\s*(.*)\s*$/; 63 if ($attributes{$attr}) { 64 if (ref $attributes{$attr}) { 65 push(@{ $attributes{$attr} }, $value); 66 } else { 67 my $temp = $attributes{$attr}; 68 $attributes{$attr} = [ $temp, $value ]; 69 } 70 } else { 71 $attributes{$attr} = $value; 72 } 73 } 74 %attributes 75 } 76 77 sub dump_read_temp_file { 78 my ($writecb, $readcb) = @_; 79 80 my ($fh, $filename) = tempfile(CLEANUP => 0); 81 $writecb->($fh) or return; 82 $fh = undef; # closing file 83 my $res; 84 85 my @stat = stat($filename); 86 while (1) { 87 my $cmd = ($ENV{EDITOR} || 'vi') . " $filename"; 88 warn "Running $cmd\n"; 89 if (system($cmd) == -1 ) { 90 warn "Cannot run editor $!\n"; 91 last; 92 } 93 if ((stat($filename))[9] == $stat[9]) { 94 warn "No change existing\n"; 95 last; 96 } 97 98 open($fh, '<', $filename) or return; 99 $res = $readcb->($fh); 100 $fh = undef; # closing again 101 $res < 2 and last; 102 } 103 unlink($filename); 104 $res; 105 } 55 106 1;
Note: See TracChangeset
for help on using the changeset viewer.