File Coverage

lib/Kephra/Edit/Special.pm
Criterion Covered Total %
statement 6 42 14.2
branch 0 16 0.0
condition 0 18 0.0
subroutine 2 6 33.3
pod 0 3 0.0
total 8 85 9.4


line stmt bran cond sub pod time code
1             package Kephra::Edit::Special;
2             $VERSION = '0.01';
3              
4 1     1   1010 use strict;
  1         2  
  1         29  
5 1     1   5 use warnings;
  1         1  
  1         512  
6              
7 0     0     sub _ep_ref { Kephra::App::EditPanel::_ref() }
8              
9             sub copy_surrounding_string { # Edit String (surrounding string encapsulated by "" or '')
10 0     0 0   my $ep = _ep_ref();
11 0           my $pos = $ep->GetCurrentPos;
12 0           my $line = $ep->GetCurrentLine;
13 0           my $lpos = $ep->PositionFromLine($line);
14 0           my $befor_text = $ep->GetTextRange($lpos, $pos);
15 0           my $after_text = $ep->GetTextRange($pos+1, $ep->GetLineEndPosition($line));
16 0           my $sq_start = rindex $befor_text, '\'';
17 0           my $sq_stop = index $after_text, '\'';
18 0           my $dq_start = rindex $befor_text, '"';
19 0           my $dq_stop = index $after_text, '"';
20 0 0 0       return if ($sq_start == -1 or $sq_stop == -1)
      0        
      0        
21             and ($dq_start == -1 or $dq_stop == -1);
22 0           Kephra::Edit::_save_positions();
23 0 0         if ($sq_start > $dq_start){$ep->SetSelection($lpos+$sq_start+1, $pos+$sq_stop+1)}
  0            
  0            
24             else {$ep->SetSelection($lpos+$dq_start+1, $pos+$dq_stop+1)}
25 0           Kephra::Edit::copy();
26 0           Kephra::Edit::_restore_positions();
27             }
28              
29             sub insert_last_perl_var {
30 0     0 0   my $ep = _ep_ref();
31 0           my $lnr = $ep->GetCurrentLine;
32 0 0         return unless $lnr;
33 0           my $pos = $ep->GetCurrentPos;
34 0           my $var; # store catched var name into that scalar
35 0           my $nl = ''; # namespace level, how nested is current ns?
36 0           while (1){
37             # go up and get me the conent of the line
38 0           my $line = $ep->GetLine(--$lnr);
39             # catch the perl var
40 0           my $result = $line =~ /([\$@%]\w+)[\[{ -=\(\r\n]/;
41 0 0         $nl++ if $line =~ /^\s*\}/;
42 0 0         $nl-- if $line =~ /\{\s*(#.*)?$/;
43 0 0         $var = $nl ? '' : $1;
44             # exit loop if found something in this , no subnamespace,
45             # or reached end of file or end of block
46 0 0 0       last if $var or $lnr == 0 or ($nl and $nl < 0);
      0        
      0        
47             }
48 0 0         return unless $var;
49 0           $ep->InsertText( $pos, $var);
50 0           $ep->GotoPos($pos + length $var);
51             }
52              
53             sub insert_time_date {
54 0     0 0   my @t = localtime;
55 0           Kephra::Edit::insert( sprintf(
56             "%02d:%02d %02d.%02d.%d",
57             $t[2],$t[1],$t[3],1+$t[4],1900+$t[5]
58             ) );
59             }
60              
61             1;