App-Tarotplane

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - tarotplane now depends on Perl 5.016.
    - CHANGELOG renamed to Changes, now follows traditional perl Changes format.
    - Switched to x.xx version number format.
  Added:
    - Tests.
    - -o option, allows you to order cards alphabetically by either terms or
      definitions.

0.3.0 Wed 2 Oct 2024
  Added:
    - Two new escape sequences:
      - \n: Force linebreak.
      - \\: Back slash.
    - Demo GIF.
  Changes:
    - Text::Wrap is now used for line wrapping.
    - Split words are no longer hyphenated.

0.2.0 Sat 17 Aug 2024
  Added:
    - '?' displays help message.

MANIFEST  view on Meta::CPAN

lib/App/Tarotplane/UI.pm
LICENSE
Makefile.PL
MANIFEST			This list of files
META.json
META.yml
README.md
t/00_load.t
t/10_cards.t
t/20_tarotplane-init.t
t/data/escape.cards
t/data/multiline.cards
t/data/sort.cards
t/data/whitespace.cards

README.md  view on Meta::CPAN

### Card Files
A **tarotplane** card file is a text file that contains cards seperated by a
delimitting line, which is a line the contains nothing but a percentage (%)
sign. Each card must contain a term and a definition, seperated by a colon (:).
Terms precede the colon, definitions follow the colon.

Lines starting with a hash (#) are treated as comments and are ignored. Blank
lines are also ignored.

#### Escape Sequences
An escape sequence is a pair of characters, a forward slash (\\) and some other
character, that enables special behavior in **tarotplane** when
reading/displaying cards. Below is a list of all the escape sequences
**tarotplane** supports:

| Escape Sequence | Behavior                  |
| --------------- | ------------------------- |
| \\\\            | Single back slash (\\)    |
| \\:             | Colon (:)                 |
| \\n             | Force linebreak           |

### Controls

bin/tarotplane  view on Meta::CPAN

  %

B<tarotplane> will only read two cards, and ignore the two empty cards between
Term 1 and Term 2.

Lines starting with a hash (#) are treated as comments and are ignored. Blank
lines are also ignored.

=head3 Escape Sequences

An escape sequence is a pair of characters, a forward slash (\) and some other
character, that signals to B<tarotplane> to perform special behavior when
reading/displaying the card. Below is a list of all the escape sequences
B<tarotplane> supports:

=over 4

=item \\

Single back slash (\).

=item \:

lib/App/Tarotplane/Cards.pm  view on Meta::CPAN

				unless $state == CARD_DEF;

			# Trim leading/trailing whitespace
			$card->{Term}       =~ s/^\s+|\s+$//g;
			$card->{Definition} =~ s/^\s+|\s+$//g;

			# Truncate whitespace
			$card->{Term}       =~ s/\s+/ /g;
			$card->{Definition} =~ s/\s+/ /g;

			## Now interpret some escape codes
			# '\:' -> ':'
			$card->{Term}       =~ s/\\:/:/g;
			$card->{Definition} =~ s/\\:/:/g;

			# '\n' -> line break
			$card->{Term}       =~ s/\\n/\n/g;
			$card->{Definition} =~ s/\\n/\n/g;

			# No longer need '\\' substitution null byte
			$card->{Term}       =~ s/\0//g;

lib/App/Tarotplane/Cards.pm  view on Meta::CPAN

			$cn++;

			next;

		}

		# Skip comments and blanks
		my $first = substr $l, 0, 1;
		next if $first eq '#' or $first eq "\n";

		# Substitute '\\' now so that '\\:' does not count as an escaped colon.
		# The null byte is added so that the subsequent substitutions do not
		# try to replace any '\\' escaped backslash.
		$l =~ s/\\\\/\\\0/g;

		if ($state == CARD_TERM) {
			# Does card contain non-escaped colon?
			if ($l =~ /(^|[^\\]):/) {
				my (undef,
					$te,
					$de
				) = split(/(^.*[^\\]):/, $l, 2);
				$card->{Term}       .= $te || '';
				$card->{Definition} .= $de || '';
				$state = CARD_DEF;
			} else {
				$card->{Term} .= $l;

t/10_cards.t  view on Meta::CPAN

	{
		Term => '5',
		Def  => '6',
	},
	{
		Term => '7',
		Def  => '8',
	},
);

my $Escape_Test = File::Spec->catfile(qw(t data escape.cards));
my $Escape_Num = 4;
my @Escape = (
	{
		Term => ":)",
		Def  => "Happy :D",
	},
	{
		Term => ":-\\",
		Def  => "Concerned\\Confused",
	},

t/10_cards.t  view on Meta::CPAN


is($d2->get('CardNum'), $Whitespace_Num, "Correct number of cards read");

foreach my $i (0 .. $Whitespace_Num) {
	is($d2->card_side($i, 'Term'), $Whitespace[$i]->{Term},
		"Card #$i term is okay (w/ weird whitespace)");
	is($d2->card_side($i, 'Definition'), $Whitespace[$i]->{Def},
		"Card #$i definition is okay (w/ weird whitespace)");
}

# Test reading escape sequences
my $d3 = App::Tarotplane::Cards->new($Escape_Test);

is($d3->get('CardNum'), $Escape_Num, "Correct number of cards read");

foreach my $i (0 .. $Escape_Num - 1) {
	is($d3->card_side($i, 'Term'), $Escape[$i]->{Term},
		"Card #$i term is okay (w/ escape sequences)");
	is($d3->card_side($i, 'Definition'), $Escape[$i]->{Def},
		"Card #$i definition is okay (w/ escape sequences)");
}

# $d4 will test reading multiple files at once
my $d4 = App::Tarotplane::Cards->new(
	$Sort_Test, $Whitespace_Test, $Escape_Test
);

is($d4->get('CardNum'), $Sort_Num + $Whitespace_Num + $Escape_Num,
	"new() correctly read multiple files at once");

t/data/escape.cards  view on Meta::CPAN

# These cards test tarotplane's escape sequences
%
\:): Happy \:D
%
\:-\\: Concerned\\Confused
%
Line\nbreak: Broken\nline
%
\\\n\\\\\:\:: All together!
%



( run in 0.416 second using v1.01-cache-2.11-cpan-5467b0d2c73 )