Using Barcode drawer for Java Control to generate, create Linear image in Java applications.

OnBarcode.com/Linear

if ($Module::Install::AUTHOR) { system('pod2text lib/Greeter/List.pm >README'); } Now any time you, the author, run Makefile.PL, the README file will be automatically generated. However, because of the author check, when an end user (or sysadmin) runs Makefile.PL, this code will be skipped and the README you shipped in your distribution will be left untouched. Back to our implementation, we can now change to the lib/ directory and replace the file Greeter.pm with the following code and some replacement stub documentation: package Greeter; use Moose; # provides warnings and strict 1; __END__ =head1 NAME Greeter =head1 SYNOPSIS Programmer's library to store and retrieve member and guest greetings for a group of named individuals.

Using Barcode drawer for Java Control to generate, create Universal Product Code version E image in Java applications.

OnBarcode.com/UCC - 12

an __END__ token on a single line after the 1; first. Note if you put all the documentation at the end of the package like this, you should be consistent. It s also possible to put documentation inline. How you do it is a matter of preference.

sub _build_greeting { my ($self) = @_; my $greeting = $self->greeting_string; my $name = $self->name $greeting =~ s/__NAME__/$name/e; return $greeting; } 1; Before we explain what all this means in the text, we ll also add some documentation. END__ =head1 NAME Greeter::Member =head1 SYNOPSIS Stores a name and a greeting, and provides a string to greet the individual by name. my $member = Greeter::Member->new( name => 'Sleepy', greeting_string => 'Night Night __NAME__' ); print $member->greeting, "\n"; The preceding documentation shows how to instantiate our object. The name attribute stores a string containing the individual s name. The greeting_string contains the greeting. Observe that we put a placeholder in where the name is to go. This is so we can greet guests later on, and so we can deal with grammatical irregularities. The name and greeting_string attributes store static string data, as shown by the isa => 'Str' type constraint. The greeting attribute is also a string, but it has a lazy_build = 1 statement indicating that it is constructed programmatically in the _build_greeting subroutine. The lazy_build key is particularly useful for computationally expensive attributes, but in this case we re using it because it s convenient. All that the _build_greeting subroutine does is substitute the __NAME__ placeholder for the name set at object construction time. It s also probably convenient to add a new method in here to greet someone else with the object s greeting. We ll leave the authorization checking for the Greeting module itself. sub greet_guest { my ($self, $name) = @_; die "A name argument is required to greet a guest" if ! $name; my $greeting = $self->greeting_string; $greeting =~ s/__NAME__/$name/; return $greeting; } We ll also have to document this method. After the print statement in the SYNOPSIS section, we can add this line:

print $member->greet_guest('Homer'), "\n"; At the end of the package, we should document the subroutine properly as well: =head1 METHODS =head2 greet_guest Receives an argument indicating the name of the guest to greet: $member->greet_guest('Bart'). Checking whether the member is authorized to greet this guest is not performed in this package. Now we can make a test file that exactly reflects the previous documentation. Put this file in t/01-Member.t: #!/usr/bin/env perl use warnings; use strict; use Test::More tests => 6; BEGIN { use_ok( 'Greeter::Member' ); } # create a Greeter::Member object my $member = Greeter::Member->new(name => 'Sleepy', greeting_string => 'Night Night __NAME__' ); # now test it works as advertised cmp_ok( ref($member), 'eq', 'Greeter::Member', "is a Greeter::Member"); cmp_ok( $member->name, 'eq', 'Sleepy', 'correct name'); cmp_ok( $member->greeting_string, 'eq' , 'Night Night __NAME__', 'correct raw greeting'); cmp_ok( $member->greeting, 'eq', 'Night Night Sleepy', "Correct actual greeting"); cmp_ok( $member->greet_guest('Homer'), 'eq', 'Night Night Homer', 'Greet guest'); This checks that the documentation works as advertised. Note that we re using the cmp_ok method, which is documented in Test::More, instead of the ok method that we used with the Point object earlier. Doing this makes it easier to write more complex test cases that require comparison not strictly necessary here, but a useful practice nonetheless. We run the test with the command prove -l t/01-Member.t, and all our tests should pass: $ prove -l t/01-Member.t t/01-Member....ok All tests successful. Files=1, Tests=6, 0 wallclock secs ( [ ... ] ) Result: PASS