FindApp::Object::State::Group::State::Dirs - Implement the FindApp group-directory set object
This is the class that each FindApp::Object::State::Group object has three of, one for each of allowed, wanted, found. Each Dirs object represents a set of paths.
Creates, initializes, and returns a Dirs object. The list is a list of filenames. As a class method:
use FindApp::Object::State::Group::Dirs; my $ob1 = FindApp::Object::State::Group::Dirs->new("lib", "t/lib");
Invoked as an instance method, the old object's contents are added to the set, making it the union of the old object set and the parameter list.
my $ob2 = $ob1->new("testlib");
Now $ob2->get returns a list of three items: lib, t/lib, and testlib.
$ob2->get
If you don't want the old object's contents, don't call it as an object method: use its class instead:
my $ob3 = $ob2->class->new("bin");
Now $ob3 will hold only the single new item.
Method used to copy an old object into a new one. This sets the new object to be the same set as the old one's only if the old one has anything in its set. So this:
$new->copy($old);
is like this:
$new->add($old->get) if $old->count;
This is called implicitly by the new method as just explained.
new
Returns the package of the blessed argument. This is useful for inherited constructors so that you don't need to know the exact class. See "new".
Returns the object itself. This is the identity function.
Overload for comparing whether two objects are truly the same reference. Used by the == and != operators.
==
!=
Overload for pretty-printing an object's contents. This is not what is used by the eq and ne operators.
eq
ne
Add a list of directories to the object. Duplicates are suppressed.
Returns true if the object has all the LIST elements, and false otherwise.
Remove all LIST elements from the object, and return those deleted.
Report how many elements are in the Dirs set.
Return one element, or undef if there isn't one. This should not exist, because these are to be thought of as sets not lists.
Return a list of the set contents in list context, and just one of them otherwise.
Clear the set, and return the deleted list.
Destructively make the current object equal to the LIST and return the object. One level of array reference will be interpolated.
Used to implement the eq operator, this compares contents.
Used to implement the == operator, this compares addresses.
The opposite of op_eq.
op_eq
The opposite of op_equals.
op_equals
If the FINDAPP_TRACE variable is set to 3 or higher, will trace some method calls.
tchrist% perl -MFindApp::Object::State::Group::Dirs -E 'say FindApp::Object::State::Group::Dirs->new(<R B G>)->add(<C M Y>)->get' BCGMRY tchrist% env FINDAPP_TRACE=3 perl -MFindApp::Object::State::Group::Dirs -E 'say FindApp::Object::State::Group::Dirs->new(<R B G>)->add(<C M Y>)->get' FindApp::Object::State::Group::Dirs::new FindApp::Object::State::Group::Dirs R B G FindApp::Object::State::Group::Dirs::add FindApp::Object::State::Group::Dirs=ARRAY(0x7f9e8b02f780) R B G FindApp::Object::State::Group::Dirs::set FindApp::Object::State::Group::Dirs=ARRAY(0x7f9e8b02f780) R B G FindApp::Object::State::Group::Dirs::add FindApp::Object::State::Group::Dirs=ARRAY(0x7f9e8b02f780) C M Y FindApp::Object::State::Group::Dirs::set FindApp::Object::State::Group::Dirs=ARRAY(0x7f9e8b02f780) B G R C M Y BCGMRY
If true, this will shorten the trace and debug output by abbreviating package names that start with "FindApp".
tchrist% FINDAPP_DEBUG_SHORTEN=1 FINDAPP_TRACE=3 perl -MFindApp::Object::State::Group::Dirs -E 'say FindApp::Object::State::Group::Dirs->new(<R B G>)->add(<C M Y>)->get' f:o:s:g:Dirs::new f:o:s:Group::Dirs R B G f:o:s:g:Dirs::add f:o:s:Group::Dirs=ARRAY(0x7fc00b030738) R B G f:o:s:g:Dirs::set f:o:s:Group::Dirs=ARRAY(0x7fc00b030738) R B G f:o:s:g:Dirs::add f:o:s:Group::Dirs=ARRAY(0x7fc00b030738) C M Y f:o:s:g:Dirs::set f:o:s:Group::Dirs=ARRAY(0x7fc00b030738) B G R C M Y BCGMRY
Which is much easier to read. The last two components in the fully-qualfied name are always left as is, with everything else clipped to a single lowercase letter and a single colon instead of a double one for the seprator.
Likewise, instead of this:
tchrist% perl -MFindApp::Object::State::Group::Dirs -e 'print FindApp::Object::State::Group::Dirs->new(<R B G>)->add(<C M Y>)' bless(["B", "C", "G", "M", "R", "Y"], "FindApp::Object::State::Group::Dirs"); # FindApp::Object::State::Group::Dirs=ARRAY(0x7fcaf302f018)
With the shortening, you get this:
tchrist% FINDAPP_DEBUG_SHORTEN=1 perl -MFindApp::Object::State::Group::Dirs -e 'print FindApp::Object::State::Group::Dirs->new(<R B G>)->add(<C M Y>)' bless(["B", "C", "G", "M", "R", "Y"], "f:o:s:Group::Dirs"); # FindApp::Object::State::Group::Dirs=ARRAY(0x7fc79102f030)
The object type in the comment is not subject to shortening.
Do not rely on the internal representation of these object being an array reference.
Tom Christiansen <tchrist@perl.com>
<tchrist@perl.com>
Copyright (c) 2016, Tom Christiansen <tchrist@perl.com>. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install FindApp, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FindApp
CPAN shell
perl -MCPAN -e shell install FindApp
For more information on module installation, please visit the detailed CPAN module installation guide.