Changeset 5312
- Timestamp:
- 06/18/09 07:59:49 (3 years ago)
- File:
-
- 1 edited
-
trunk/Padre/lib/Padre/Search.pm (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/lib/Padre/Search.pm
r5257 r5312 11 11 # Create the search object 12 12 my $search = Padre::Search->new( 13 find_te xt=> 'foo',13 find_term => 'foo', 14 14 ); 15 15 16 16 # Execute the search on an editor object 17 $search->find_ down($editor);17 $search->find_next(Padre::Current->editor); 18 18 19 19 =head2 DESCRIPTION … … 36 36 use Class::XSAccessor 37 37 getters => { 38 find_te xt => 'find_text',38 find_term => 'find_term', 39 39 find_case => 'find_case', 40 40 find_regex => 'find_regex', 41 41 find_reverse => 'find_reverse', 42 replace_term => 'replace_term', 43 search_regex => 'search_regex', 42 44 }; 43 45 … … 45 47 my $class = shift; 46 48 my $self = bless { @_ }, $class; 47 unless ( defined $self->find_te xt) {48 die("Did not provide 'find_te xt' search term");49 unless ( defined $self->find_term ) { 50 die("Did not provide 'find_term' search term"); 49 51 } 50 52 unless ( defined $self->find_case ) { … … 58 60 } 59 61 60 # Generate the regex form of the search 61 my $term = ''; 62 # Escape the raw search term 63 my $term = $self->find_term; 64 if ( $self->find_regex ) { 65 # Escape non-trailing $ so they won't interpolate 66 $term =~ s/\$(?!\z)/\\\$/g; 67 } else { 68 # Escape everything 69 $term = quotemeta $term; 70 } 71 72 # Compile the regex 73 $self->{search_regex} = eval { 74 $self->find_case ? qr/$term/m : qr/$term/mi 75 }; 76 if ( $@ ) { 77 # The regex doesn't compile 78 return; 79 } 62 80 63 81 return $self; … … 77 95 78 96 ##################################################################### 79 # DirectionAbstraction97 # Command Abstraction 80 98 81 99 sub search_next { … … 98 116 99 117 sub replace_next { 100 my $self = shift; 101 my $editor = shift; 102 unless ( _INSTANCE($editor, 'Padre::Wx::Editor') ) { 103 die("Failed to provide editor object to replace in"); 104 } 118 my $self = shift; 105 119 106 120 # Replace the currently selected match 107 $self->replace( $editor);121 $self->replace(@_); 108 122 109 123 # Select and move to the next match 110 124 if ( $self->config->find_reverse ) { 111 return $self->search_down( $editor);112 } else { 113 return $self->search_up( $editor);125 return $self->search_down(@_); 126 } else { 127 return $self->search_up(@_); 114 128 } 115 129 } … … 117 131 sub replace_previous { 118 132 my $self = shift; 119 my $editor = shift;120 unless ( _INSTANCE($editor, 'Padre::Wx::Editor') ) {121 die("Failed to provide editor object to replace in");122 }123 133 124 134 # Replace the currently selected match 125 $self->replace( $editor);135 $self->replace(@_); 126 136 127 137 # Select and move to the next match 128 138 if ( $self->config->find_reverse ) { 129 return $self->search_up( $editor);130 } else { 131 return $self->search_down( $editor);139 return $self->search_up(@_); 140 } else { 141 return $self->search_down(@_); 132 142 } 133 143 } … … 138 148 139 149 ##################################################################### 140 # Search Methods150 # Content Abstraction 141 151 142 152 sub search_down { 153 my $self = shift; 154 if ( _INSTANCE($_[0], 'Padre::Wx::Editor') ) { 155 return $self->editor_search_down(@_); 156 } 157 die("Missing or invalid content object to search in"); 158 } 159 160 sub search_up { 161 my $self = shift; 162 if ( _INSTANCE($_[0], 'Padre::Wx::Editor') ) { 163 return $self->editor_search_up(@_); 164 } 165 die("Missing or invalid content object to search in"); 166 } 167 168 sub replace { 169 my $self = shift; 170 if ( _INSTANCE($_[0], 'Padre::Wx::Editor') ) { 171 return $self->editor_replace(@_); 172 } 173 die("Missing or invalid content object to search in"); 174 } 175 176 sub replace_all { 177 my $self = shift; 178 if ( _INSTANCE($_[0], 'Padre::Wx::Editor') ) { 179 return $self->editor_replace_all(@_); 180 } 181 die("Missing or invalid content object to search in"); 182 } 183 184 185 186 187 188 ##################################################################### 189 # Editor Interaction 190 191 sub editor_search_down { 143 192 my $self = shift; 144 193 my $editor = shift; … … 160 209 } 161 210 162 sub search_up {211 sub editor_search_up { 163 212 my $self = shift; 164 213 my $editor = shift; … … 181 230 } 182 231 183 sub replace {232 sub editor_replace { 184 233 my $self = shift; 185 234 my $editor = shift; … … 204 253 } 205 254 206 sub replace_all {255 sub editor_replace_all { 207 256 my $self = shift; 208 257 my $editor = shift; … … 236 285 237 286 238 239 287 ##################################################################### 240 # The ActualSearch288 # Core Search 241 289 242 290 =pod
Note: See TracChangeset
for help on using the changeset viewer.
