#!/usr/bin/perl
use strict; use warnings;

=pod

=encoding UTF-8

=head1 NAME

project-token-name - Print the token name of the project based in the working directory

=head1 SYNOPSIS

project-token-name

perldoc project-token-name

=head1 DESCRIPTION

This works as advertised only if the working directory is the base directory of a project.

Prints the token name of the project whose proper path ends (or would end) in the working directory.
The token name is a URL friendly, file-system friendly name that is useable as a simple path name
and unique among my active projects.  Usually it equals the proper, Java package name of the project.
However, if the package name is too unlike the proper name of the project as spoken, then the token name
is the proper name transformed as necessary to meet the conditions of a token name.

Fails with an error message if the working directory is detected to be outside of the command directory
or one that is structurally mapped to it.

=head1 EXAMPLES

 ~/work/wayic/cast> project-token-name

    → wayic.cast

 ~/var/repo/git/wayic.cast.git> project-token-name

    → wayic.cast

 ~/work/wayic/Waybrec> project-token-name

    → Waybrec

 ~/var/repo/git/Waybrec.git> project-token-name

    → Waybrec

=head1 SEE ALSO

http://reluk.ca/project/building/lexicon.brec §§ command directory, proper package, proper path

http://reluk.ca/project/editing/action_plan.brec § proper names

project-proper-path

=cut
{

    my $p =`pwd`;
    chomp $p;
    if( $p =~ s'^/home/mike/(?:code/WP3|project|work)/'' ) {
        ex: { # Exceptional cases.  Each is recursive, including the subprojects as well.
            $p =~ s'^Breccia/XML/translator\b'Breccia_to_X-Breccia' and last ex;
              # Not ‘Breccia.XML.translator’, but ‘Breccia_to_X-Breccia’.
            $p =~ s'^Breccia/XML\b'X-Breccia'      and last ex;
              # Not ‘Breccia.XML’, but ‘X-Breccia’.
            $p =~ s'^Java/Emacs\b'Java_Mode_Tamed' and last ex;
              # Not ‘Java.Emacs’, but ‘Java_Mode_Tamed’.
            $p =~ s'^wayic/(?=Waybrec\b)''         and last ex; }
              # Not ‘wayic.Waybrec’, but ‘Waybrec’.
        $p =~ s'/'.'g; }
    elsif( $p !~ s'^/home/mike/var/repo/git/(.+)\.git'$1' ) {
        die "Not a project directory\n"; }
    print $p;
    print "\n"; }


__END__

=pod

=head1 AUTHOR

Michael Allan <mike@reluk.ca>

=cut