Text::Snippet::TabStop::WithDefault - Tab stop that specifies a default value for the user


Text-Snippet documentation Contained in the Text-Snippet distribution.

Index


Code Index:

NAME

Top

Text::Snippet::TabStop::WithDefault - Tab stop that specifies a default value for the user

VERSION

Top

version 0.04

EXAMPLE SYNTAX

Top

	${1:default value here}

CLASS METHODS

Top

parse

This method parses the index and default value from the source that is passed in.

INSTANCE METHODS

Top

* default

Returns the default value as parsed from the original source of the tab stop.

* replacement

Augments super-class' replacement method an returns the default value if no replacement has been specified.

AUTHOR

Top

  Brian Phillips <bphillips@cpan.org>

COPYRIGHT AND LICENSE

Top


Text-Snippet documentation Contained in the Text-Snippet distribution.

package Text::Snippet::TabStop::WithDefault;
BEGIN {
  $Text::Snippet::TabStop::WithDefault::VERSION = '0.04';
}

# ABSTRACT: Tab stop that specifies a default value for the user

use strict;
use warnings;
use base qw(Text::Snippet::TabStop);
use Carp qw(croak);
use Class::XSAccessor getters => { default => 'default' };


sub replacement {
	my $self = shift;
	return $self->has_replacement ? $self->SUPER::replacement : $self->default;
}

sub parse {
	my $class = shift;
	my $src = shift;
	if($src =~ m/\$\{(\d+):(.*)\}/){
		return $class->_new( index => $1, src => $src, default => $2 || '' );
	}
	return;
}

1;

__END__