| 1 | package Tail::Tool::Regex; | ||||||||||
| 2 | |||||||||||
| 3 | # Created on: 2011-03-10 17:42:50 | ||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||
| 5 | # $Id$ | ||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||
| 8 | |||||||||||
| 9 | 7 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 7 | ▶ | use version; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 7 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 7 | ▶ | use English qw/ -no_match_vars /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 7 | ▶ | use Term::ANSIColor qw/colored/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 7 | our $VERSION = version->new('0.4.5'); | |||||||||
| 17 | |||||||||||
| 18 | coerce 'RegexpRef' | ||||||||||
| 19 | => from 'Str' | ||||||||||
| 20 | 3 | ▶ | => via { qr/$_/ }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 7 | has regex => ( | |||||||||
| 23 | is => 'rw', | ||||||||||
| 24 | isa => 'RegexpRef', | ||||||||||
| 25 | default => qw/^/, | ||||||||||
| 26 | coerce => 1, | ||||||||||
| 27 | required => 1, | ||||||||||
| 28 | ); | ||||||||||
| 29 | 7 | has replace => ( | |||||||||
| 30 | is => 'rw', | ||||||||||
| 31 | isa => 'Str', | ||||||||||
| 32 | predicate => 'has_replace', | ||||||||||
| 33 | ); | ||||||||||
| 34 | 7 | has colour => ( | |||||||||
| 35 | is => 'rw', | ||||||||||
| 36 | isa => 'ArrayRef[Str]', | ||||||||||
| 37 | predicate => 'has_colour', | ||||||||||
| 38 | ); | ||||||||||
| 39 | 7 | has enabled => ( | |||||||||
| 40 | is => 'rw', | ||||||||||
| 41 | isa => 'Bool', | ||||||||||
| 42 | default => 1, | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | sub summarise { | ||||||||||
| 46 | 20 | ▶ | my ($self, $term) = @_; | ||||||||
|
Subroutine
summarise: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||
| 47 | |||||||||||
| 48 | 20 | my $text = "qr/" . $self->regex . "/"; | |||||||||
| 49 | |||||||||||
| 50 | 20 | ▶ | if ( $self->has_replace ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 4 | $text .= $self->replace . '/'; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 20 | ▶ | if ( $self->has_colour ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | $text = | ||||||||||
| 56 | 0 | $term ? colored( $text, join ' ', @{ $self->colour } ) | |||||||||
| 57 | 2 | ▶ | : $text . ', colour=[' . ( join ', ', @{ $self->colour } ) . ']'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 20 | ▶ | if ( !$self->enabled ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 2 | ▶ | $text = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | $term ? colored( "[$text]", 'reverse' ) | ||||||||||
| 63 | : $text . ', disabled'; | ||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 20 | return $text; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 7 | 1; | |||||||||
| 70 | |||||||||||
| 71 | __END__ | ||||||||||
| 72 | |||||||||||
| 73 | =head1 NAME | ||||||||||
| 74 | |||||||||||
| 75 | Tail::Tool::Regex - Base class for regex details | ||||||||||
| 76 | |||||||||||
| 77 | =head1 VERSION | ||||||||||
| 78 | |||||||||||
| 79 | This documentation refers to Tail::Tool::Regex version 0.4.5. | ||||||||||
| 80 | |||||||||||
| 81 | =head1 SYNOPSIS | ||||||||||
| 82 | |||||||||||
| 83 | use Tail::Tool::Regex; | ||||||||||
| 84 | |||||||||||
| 85 | # create a new object with a regex reference | ||||||||||
| 86 | my $regex = Tail::Tool::Regex->new( regex => qr/^find/ ); | ||||||||||
| 87 | |||||||||||
| 88 | # if a string is passed it will be coerced into a regex reference | ||||||||||
| 89 | $regex = Tail::Tool::Regex->new( regex => '^find' ); | ||||||||||
| 90 | |||||||||||
| 91 | # if replacement is to be done specify a replacement string | ||||||||||
| 92 | $regex = Tail::Tool::Regex->new( | ||||||||||
| 93 | regex => qr/find$/, | ||||||||||
| 94 | replace => 'found', | ||||||||||
| 95 | ); | ||||||||||
| 96 | |||||||||||
| 97 | # if the regex is used for colouring specify the colours | ||||||||||
| 98 | $regex = Tail::Tool::Regex->new( | ||||||||||
| 99 | regex => qr/find$/, | ||||||||||
| 100 | colour => [qw/red on_green/], | ||||||||||
| 101 | ); | ||||||||||
| 102 | |||||||||||
| 103 | # The regex can be set to being disabled initially | ||||||||||
| 104 | $regex = Tail::Tool::Regex->new( | ||||||||||
| 105 | regex => qr/find/, | ||||||||||
| 106 | enabled => 0, | ||||||||||
| 107 | ); | ||||||||||
| 108 | |||||||||||
| 109 | =head1 DESCRIPTION | ||||||||||
| 110 | |||||||||||
| 111 | =head1 SUBROUTINES/METHODS | ||||||||||
| 112 | |||||||||||
| 113 | =head2 C<summarise ( [$term] )> | ||||||||||
| 114 | |||||||||||
| 115 | Returns a summary of this modules settings, if C<$term> is true the string is | ||||||||||
| 116 | coloured for terminal displays. | ||||||||||
| 117 | |||||||||||
| 118 | =head1 DIAGNOSTICS | ||||||||||
| 119 | |||||||||||
| 120 | A list of every error and warning message that the module can generate (even | ||||||||||
| 121 | the ones that will "never happen"), with a full explanation of each problem, | ||||||||||
| 122 | one or more likely causes, and any suggested remedies. | ||||||||||
| 123 | |||||||||||
| 124 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||
| 125 | |||||||||||
| 126 | A full explanation of any configuration system(s) used by the module, including | ||||||||||
| 127 | the names and locations of any configuration files, and the meaning of any | ||||||||||
| 128 | environment variables or properties that can be set. These descriptions must | ||||||||||
| 129 | also include details of any configuration language used. | ||||||||||
| 130 | |||||||||||
| 131 | =head1 DEPENDENCIES | ||||||||||
| 132 | |||||||||||
| 133 | A list of all of the other modules that this module relies upon, including any | ||||||||||
| 134 | restrictions on versions, and an indication of whether these required modules | ||||||||||
| 135 | are part of the standard Perl distribution, part of the module's distribution, | ||||||||||
| 136 | or must be installed separately. | ||||||||||
| 137 | |||||||||||
| 138 | =head1 INCOMPATIBILITIES | ||||||||||
| 139 | |||||||||||
| 140 | A list of any modules that this module cannot be used in conjunction with. | ||||||||||
| 141 | This may be due to name conflicts in the interface, or competition for system | ||||||||||
| 142 | or program resources, or due to internal limitations of Perl (for example, many | ||||||||||
| 143 | modules that use source code filters are mutually incompatible). | ||||||||||
| 144 | |||||||||||
| 145 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 146 | |||||||||||
| 147 | A list of known problems with the module, together with some indication of | ||||||||||
| 148 | whether they are likely to be fixed in an upcoming release. | ||||||||||
| 149 | |||||||||||
| 150 | Also, a list of restrictions on the features the module does provide: data types | ||||||||||
| 151 | that cannot be handled, performance issues and the circumstances in which they | ||||||||||
| 152 | may arise, practical limitations on the size of data sets, special cases that | ||||||||||
| 153 | are not (yet) handled, etc. | ||||||||||
| 154 | |||||||||||
| 155 | The initial template usually just has: | ||||||||||
| 156 | |||||||||||
| 157 | There are no known bugs in this module. | ||||||||||
| 158 | |||||||||||
| 159 | Please report problems to Ivan Wills (ivan.wills@gmail.com). | ||||||||||
| 160 | |||||||||||
| 161 | Patches are welcome. | ||||||||||
| 162 | |||||||||||
| 163 | =head1 AUTHOR | ||||||||||
| 164 | |||||||||||
| 165 | Ivan Wills - (ivan.wills@gmail.com) | ||||||||||
| 166 | <Author name(s)> (<contact address>) | ||||||||||
| 167 | |||||||||||
| 168 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 169 | |||||||||||
| 170 | Copyright (c) 2011 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). | ||||||||||
| 171 | All rights reserved. | ||||||||||
| 172 | |||||||||||
| 173 | This module is free software; you can redistribute it and/or modify it under | ||||||||||
| 174 | the same terms as Perl itself. See L<perlartistic>. This program is | ||||||||||
| 175 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||||||||||
| 176 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||
| 177 | PARTICULAR PURPOSE. | ||||||||||
| 178 | |||||||||||
| 179 | =cut | ||||||||||