in lib/ES/Book.pm [74:174]
sub new {
#===================================
my ( $class, %args ) = @_;
my $title = $args{title}
or die "No <title> specified: " . Dumper( \%args );
my $source = ES::Source->new(
temp_dir => $args{temp_dir},
sources => $args{sources},
examples => $args{examples},
);
my $prefix = $args{prefix}
or die "No <prefix> specified for book <$title>";
my $index = Path::Class::file( $args{index} || 'index.asciidoc' );
my $chunk = $args{chunk} || 0;
my $toc = $args{toc} || 0;
my $branch_list = $args{branches};
my $current = $args{current};
die "<branches> must be an array in book <$title>"
unless ref $branch_list eq 'ARRAY';
# Each branch can be either a single value, or a mapping of
# {<branch_name>: <title>}. Branch titles are used in the version dropdown
# and version lists.
my ( @branches, %branch_titles );
for (@$branch_list) {
my ( $branch, $title ) = ref $_ eq 'HASH' ? (%$_) : ( $_, $_ );
push @branches, $branch;
$branch_titles{$branch} = $title;
}
die "Current branch <$current> is not in <branches> in book <$title>"
unless $branch_titles{$current};
my $live_branches = $args{live};
# If `live` is defined, check if there are any specified branches that
# aren't in the list of branches being built.
my @difference;
foreach my $item (@$live_branches) {
push @difference, $item unless grep { $item eq $_ } @branches;
}
# print "Branches: ", join(", ", @branches), "\n";
# print "Live: ", join(", ", @$live_branches), "\n";
# print "Difference: ", join(", ", @difference), "\n";
my $missing = join ", ", @difference;
die "Live branch(es) <$missing> not in <branches> in book <$title>"
if $difference[0];
my $tags = $args{tags}
or die "No <tags> specified for book <$title>";
my $subject = $args{subject}
or die "No <subject> specified for book <$title>";
my $lang = $args{lang} || 'en';
my $respect_edit_url_overrides = 0;
if (exists $args{respect_edit_url_overrides}) {
$respect_edit_url_overrides = $args{respect_edit_url_overrides};
if ($respect_edit_url_overrides eq 'true') {
$respect_edit_url_overrides = 1;
} elsif ($respect_edit_url_overrides eq 'false') {
$respect_edit_url_overrides = 0;
} else {
die 'respect_edit_url_overrides must be true or false but was ' . $respect_edit_url_overrides;
}
}
bless {
title => $title,
raw_dir => $args{raw_dir}->subdir( $prefix ),
dir => $args{dir}->subdir( $prefix ),
temp_dir => $args{temp_dir},
source => $source,
prefix => $prefix,
chunk => $chunk,
toc => $toc,
single => $args{single},
index => $index,
branches => \@branches,
live_branches => $args{live} || \@branches,
branch_titles => \%branch_titles,
current => $current,
tags => $tags,
subject => $subject,
private => $args{private} || '',
noindex => $args{noindex} || '',
lang => $lang,
respect_edit_url_overrides => $respect_edit_url_overrides,
suppress_migration_warnings => $args{suppress_migration_warnings} || 0,
toc_extra => $args{toc_extra} || '',
}, $class;
}