Aion-Format

 view release on metacpan or  search on metacpan

lib/Aion/Format.pm  view on Meta::CPAN

	    qr/(?<num> \d+)/x   => sub { "($+{num})" },
	    qr/\b pi \b/x       => sub { 3.14 },
	    qr/(?<op> \*)/x     => sub { " $& " },
	;
	
	$s # => (33) * 3.14

=head2 matches ($subject, @rules)

Synonym for C<replace>. B<DEPRECATED>.

	my $s = matches "33*pi",
	    qr/(?<num> \d+)/x   => sub { "($+{num})" },
	    qr/\b pi \b/x       => sub { 3.14 },
	    qr/(?<op> \*)/x     => sub { " $& " },
	;
	
	$s # => (33) * 3.14

=head2 nous ($templates)

A simplified regular expression language for text recognition in HTML documents.

=over

=item 1. Removes all spaces at the beginning and end.

=item 2. From the beginning of each line, 4 spaces or 0-3 spaces and a tab are removed.

=item 3. Spaces at the end of a line and strings of spaces are replaced with C<\s*>.

=item 4. All variables in C<{{ var }}> are replaced with C<.*?>. Those. everything is recognized.

=item 5. All variables in C<< {{E<gt> var }} >> are replaced with C<< [^E<lt>E<gt>]*? >>. Those. HTML tags are not recognized.

=item 6. All variables in C<{{: var }}> are replaced with C<[^\n]*>. Those. must be on one line.

=item 7. Expressions in double square brackets (C<[[ ... ]]>) may not exist.

=item 8. Double brackets (C<(( ... ))> are used as parentheses.

=item 9. C<||> - or.

=back

	my $re = nous [
	q{
		<body>
		<center>
		<h2><a href={{> author_link }}>{{: author_name }}</a><br>
		{{ title }}</h2>
	},
	q{
	    <li><A HREF="{{ comments_link }}">((Comments: {{ comments }}, last from {{ last_comment_posted }}.||Added comment))</A>
		<li><a href="{{ author_link }}">{{ author_name }}</a>
		[[ (translate: {{ interpreter_name }})]]
		 (<u>{{ author_email }}</u>) 
		<li>Year: {{ posted }}
	},
	q{
		<li><B><font color=#393939>Annotation:</font></b><br><i>{{ annotation_html }}</i></ul>
		</ul></font>
		</td></tr>
	},
	q{
		<!----------- The work itself --------------->
		{{ html }}
		<!------------------------------------------->
	},
	];
	
	my $s = q{
	<body>
	<center>
	<h2><a href=/to/book/link>A. Alis</a><br>
	Grivus campf</h2>
	
	Any others...
	
	<!----------- The work itself --------------->
	This book text!
	<!------------------------------------------->
	};
	
	$s =~ $re;
	my $result = {%+};
	$result # --> {author_link => "/to/book/link", author_name => "A. Alis", title => "Grivus campf"}

=head2 num ($number)

Adds separators between digits of a number.

	num +0         # => 0
	num -1000.3    # => -1 000.3

The default separator is a non-breaking space. Set the separator and decimal point the same way:

	num [1000, "#"]         		# => 1#000
	num [-1000.3003003, "_", ","]   # => -1_000,3003003

See also C<Number::Format>.

=head2 rim ($number)

Converts positive integers to B<Roman numerals>.

	rim 0       # => N
	rim 4       # => IV
	rim 6       # => VI
	rim 50      # => L
	rim 49      # => XLIX
	rim 505     # => DV

B<Roman numerals> after 1000:

	rim 49_000      # => XLIX M
	rim 49_000_000  # => XLIX M M
	rim 49_009_555  # => XLIX IX DLV

See also:

=over



( run in 2.250 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )