Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kfly8 committed Aug 19, 2024
1 parent a49c4bd commit 7c9baae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ hello(); # => Dies when STRICT mode is enabled

Syntax::Keyword::Assert introduces a lightweight assert keyword to Perl, designed to provide runtime assertions with minimal overhead.

\- **STRICT Mode**: When STRICT mode is enabled, assert statements are checked at runtime. If the assertion fails (i.e., the block returns false), the program dies with an error. This is particularly useful for catching errors during development or testing.
- **STRICT Mode**

\- **Zero Runtime Cost**: When STRICT mode is disabled, the assert blocks are completely ignored at compile time, resulting in zero runtime cost. This makes Syntax::Keyword::Assert ideal for use in production environments, as it does not introduce any performance penalties when assertions are not needed.
When STRICT mode is enabled, assert statements are checked at runtime. If the assertion fails (i.e., the block returns false), the program dies with an error. This is particularly useful for catching errors during development or testing.

\- **Simple Syntax**: The syntax is straightforward—assert BLOCK—making it easy to integrate into existing codebases.
- **Zero Runtime Cost**

When STRICT mode is disabled, the assert blocks are completely ignored at compile phase, resulting in zero runtime cost. This makes Syntax::Keyword::Assert ideal for use in production environments, as it does not introduce any performance penalties when assertions are not needed.

- **Simple Syntax**

The syntax is straightforward—assert BLOCK—making it easy to integrate into existing codebases.

## STRICT Mode Control

Expand Down Expand Up @@ -59,9 +65,12 @@ SEE ALSO:

## Verbose error messages

If you want to see more detailed error messages when an assertion fails, you can enable Carp::Verbose:
If you set `$Carp::Verbose = 1`, you can see stack traces when an assertion fails.

```perl
use Syntax::Keyword::Assert;
use Carp;

```
assert {
local $Carp::Verbose = 1;
0;
Expand All @@ -70,7 +79,13 @@ assert {

# SEE ALSO

[PerlX::Assert](https://metacpan.org/pod/PerlX%3A%3AAssert), [Devel::Assert](https://metacpan.org/pod/Devel%3A%3AAssert), [Carp::Assert](https://metacpan.org/pod/Carp%3A%3AAssert)
- [PerlX::Assert](https://metacpan.org/pod/PerlX%3A%3AAssert)

This module also uses keyword plugin, but it depends on [Keyword::Simple](https://metacpan.org/pod/Keyword%3A%3ASimple).

- [Devel::Assert](https://metacpan.org/pod/Devel%3A%3AAssert)

This module provides a similar functionality, but it dose not use a keyword plugin.

# LICENSE

Expand Down
33 changes: 28 additions & 5 deletions lib/Syntax/Keyword/Assert.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ Syntax::Keyword::Assert - assert keyword for Perl with zero runtime cost in prod
Syntax::Keyword::Assert introduces a lightweight assert keyword to Perl, designed to provide runtime assertions with minimal overhead.
- B<STRICT Mode>: When STRICT mode is enabled, assert statements are checked at runtime. If the assertion fails (i.e., the block returns false), the program dies with an error. This is particularly useful for catching errors during development or testing.
=over 4
- B<Zero Runtime Cost>: When STRICT mode is disabled, the assert blocks are completely ignored at compile time, resulting in zero runtime cost. This makes Syntax::Keyword::Assert ideal for use in production environments, as it does not introduce any performance penalties when assertions are not needed.
=item B<STRICT Mode>
- B<Simple Syntax>: The syntax is straightforward—assert BLOCK—making it easy to integrate into existing codebases.
When STRICT mode is enabled, assert statements are checked at runtime. If the assertion fails (i.e., the block returns false), the program dies with an error. This is particularly useful for catching errors during development or testing.
=item B<Zero Runtime Cost>
When STRICT mode is disabled, the assert blocks are completely ignored at compile phase, resulting in zero runtime cost. This makes Syntax::Keyword::Assert ideal for use in production environments, as it does not introduce any performance penalties when assertions are not needed.
=item B<Simple Syntax>
The syntax is straightforward—assert BLOCK—making it easy to integrate into existing codebases.
=back
=head2 STRICT Mode Control
Expand Down Expand Up @@ -102,7 +112,10 @@ L<Bench | https://github.com/kfly8/Syntax-Keyword-Assert/blob/main/bench/compare
=head2 Verbose error messages
If you want to see more detailed error messages when an assertion fails, you can enable Carp::Verbose:
If you set C<$Carp::Verbose = 1>, you can see stack traces when an assertion fails.
use Syntax::Keyword::Assert;
use Carp;
assert {
local $Carp::Verbose = 1;
Expand All @@ -111,7 +124,17 @@ If you want to see more detailed error messages when an assertion fails, you can
=head1 SEE ALSO
L<PerlX::Assert>, L<Devel::Assert>, L<Carp::Assert>
=over 4
=item L<PerlX::Assert>
This module also uses keyword plugin, but it depends on L<Keyword::Simple>.
=item L<Devel::Assert>
This module provides a similar functionality, but it dose not use a keyword plugin.
=back
=head1 LICENSE
Expand Down

0 comments on commit 7c9baae

Please sign in to comment.