App-Sqitch
view release on metacpan or search on metacpan
lib/App/Sqitch/Plan.pm view on Meta::CPAN
$line =~ /
^ # Beginning of line
(?<lspace>[[:blank:]]*)? # Optional leading space
(?: # followed by...
[@] # @ for tag
| # ...or...
(?<lopspace>[[:blank:]]*) # Optional blanks
(?<operator>[+-]) # Required + or -
(?<ropspace>[[:blank:]]*) # Optional blanks
)? # ... optionally
(?<name>$name_re) # followed by name
(?<pspace>[[:blank:]]+)? # blanks
(?: # followed by...
[[](?<dependencies>[^]]+)[]] # dependencies
[[:blank:]]* # blanks
)? # ... optionally
(?: # followed by...
$ts_re # timestamp
[[:blank:]]* # blanks
)? # ... optionally
(?: # followed by
$planner_re # planner
)? # ... optionally
$ # end of line
/x;
%params = ( %params, %+ );
# Raise errors for missing data.
$raise_syntax_error->(__(
qq{Invalid name; names must not begin with punctuation, }
. 'contain "@", ":", "#", "\\", "[", "]", or blanks, or end in punctuation or digits following punctuation',
)) if !$params{name}
|| (!$params{yr} && $line =~ $ts_re);
$raise_syntax_error->(__ 'Missing timestamp and planner name and email')
unless $params{yr} || $params{planner_name};
$raise_syntax_error->(__ 'Missing timestamp') unless $params{yr};
$raise_syntax_error->(__ 'Missing planner name and email')
unless $params{planner_name};
# It must not be a reserved name.
$raise_syntax_error->(__x(
'"{name}" is a reserved name',
name => ($type eq 'tag' ? '@' : '') . $params{name},
)) if exists $reserved{ $params{name} };
# It must not look like a SHA1 hash.
$raise_syntax_error->(__x(
'"{name}" is invalid because it could be confused with a SHA1 ID',
name => $params{name},
)) if $params{name} =~ /^[0-9a-f]{40}/;
# Assemble the timestamp.
require App::Sqitch::DateTime;
$params{timestamp} = App::Sqitch::DateTime->new(
year => delete $params{yr},
month => delete $params{mo},
day => delete $params{dy},
hour => delete $params{hr},
minute => delete $params{mi},
second => delete $params{sc},
time_zone => 'UTC',
);
if ($type eq 'tag') {
# Faile if contains directory separators
if ($params{name} =~ qr/($dir_sep_re)/) {
$raise_syntax_error->(__x(
'Tag "{tag}" contains illegal character {sep}',
tag => $params{name},
sep => $1,
));
}
# Fail if no changes.
unless ($prev_change) {
$raise_syntax_error->(__x(
'Tag "{tag}" declared without a preceding change',
tag => $params{name},
));
}
# Fail on duplicate tag.
my $key = '@' . $params{name};
if ( my $at = $line_no_for{$key} ) {
$raise_syntax_error->(__x(
'Tag "{tag}" duplicates earlier declaration on line {line}',
tag => $params{name},
line => $at,
));
}
# Fail on dependencies.
$raise_syntax_error->(__x(
__ 'Tags may not specify dependencies'
)) if $params{dependencies};
if (@curr_changes) {
# Sort all changes up to this tag by their dependencies.
push @changes => $self->check_changes(
$pragmas{project},
\%line_no_for,
@curr_changes,
);
@curr_changes = ();
}
# Create the tag and associate it with the previous change.
$prev_tag = App::Sqitch::Plan::Tag->new(
plan => $self,
change => $prev_change,
%params,
);
# Keep track of everything and clean up.
( run in 0.872 second using v1.01-cache-2.11-cpan-99c4e6809bf )