SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Common Boolean Class
for Perl 5
Kenichi Ishigaki
@charsbar
TPC in Glasgow 2018
Aug 16, 2018
me
• DBD::SQLite
• CPANTS
• PAUSE on Mojolicious
• JSON/JSON::PP
• Text::CSV/Text::CSV_PP
Boolean is really simple
It has only two states:
TRUE or FALSE
Boolean in Perl 5 is not
that simple
Because we don't have native boolean
Typical implementation of
boolean in Perl 5
my $true = 1;
my $false = 0;
$T = bless $true, $boolean_class;
$F = bless $false, $boolean_class;
(with some overload configuration)
What if a "boolean" object
is embedded in a string?
• use overload to convert them into
"true" or "false"?
• ... if "$false"; # but true
• say "This is " .
($bool->isa($boolean_class)
? ($bool ? "true" : "false")
: $bool); # ugly
How can you tell if
it's a boolean?
• MetaCPAN returns 1877 results
when you search "Bool"...
• Not all of them represent
boolean, though...
Don't worry too much
All of them should work in
the Perl context, at least
as long as you use them in
the boolean context
Until you start
serializing your data
JSON modules only accept
JSON::PP::Boolean objects
(or their aliases) by default
Luckily JSON::PP::Boolean
is in Perl 5 core now
• You can use it as a default
boolean class
• Do you want to use JSON::PP
just to get boolean objects?
How about boolean.pm?
• It would have been nice if it were
more widely adopted
• Unfortunately it is not supported
by JSON modules by default
Or Types::Serialiser?
• It provides boolean objects that are
JSON::PP::Boolean
• It has a more neutral name for CBOR::XS
• It's not in core, so it's hard to adopt for
toolchain modules or the likes
Then what to do?
• Add something into core?
• Or just use the same
convention under the hood?
• Or else?
The bottomline
• The new stuff should work
with existing modules
• Otherwise you can't use it
for interoperability
Two new candidates
bool.pm
• Written by Tina Mueller as a
proof of concept at PTS 2018
• Not yet CPANized
https://github.com/perlpunk/bool-p5/tree/json-pp-compat
Types::Bool
• Written by Adriano Ferreira,
inspired by Tina's PTS report
• Works quite similar to
Types::Serialiser
https://metacpan.org/pod/Types::Bool
There are still issues
to be solved
• bool namespace and Perl 6?
• Types:: namespace is reserved
for a different purpose?
• duplicated effort?
• and probably more
Further reading
• "My report of the Perl Toolchain Summit
2018 in Oslo" by Tina Mueller
http://blogs.perl.org/users/tinita/2018/05/my-report-of-the-
perl-toolchain-summit-2018-in-oslo.html
• "[Work in Progress] Boolean support with
Types::Bool"
https://github.com/makamaka/JSON-PP/pull/36
Let us know
your thoughts
Thanks

Weitere ähnliche Inhalte

Mehr von charsbar

CPANTS 2012
CPANTS 2012CPANTS 2012
CPANTS 2012
charsbar
 

Mehr von charsbar (20)

2018年夏のPerl5
2018年夏のPerl52018年夏のPerl5
2018年夏のPerl5
 
萬國之津梁
萬國之津梁萬國之津梁
萬國之津梁
 
Better detection of what modules are used by some Perl 5 code
Better detection of what modules are used by some Perl 5 codeBetter detection of what modules are used by some Perl 5 code
Better detection of what modules are used by some Perl 5 code
 
2017年夏のPerl
2017年夏のPerl2017年夏のPerl
2017年夏のPerl
 
2017年春のPerl
2017年春のPerl2017年春のPerl
2017年春のPerl
 
Json(::PP) is a-changing
Json(::PP) is a-changingJson(::PP) is a-changing
Json(::PP) is a-changing
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)
 
JSON, JSON::PP, and more
JSON, JSON::PP, and moreJSON, JSON::PP, and more
JSON, JSON::PP, and more
 
perl language update
perl language updateperl language update
perl language update
 
CPANの依存モジュールをもう少し正しく検出したい
CPANの依存モジュールをもう少し正しく検出したいCPANの依存モジュールをもう少し正しく検出したい
CPANの依存モジュールをもう少し正しく検出したい
 
2013年のCPANモジュール作成事情
2013年のCPANモジュール作成事情2013年のCPANモジュール作成事情
2013年のCPANモジュール作成事情
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLite
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
 
Analyze CPAN, Analyze Community
Analyze CPAN, Analyze CommunityAnalyze CPAN, Analyze Community
Analyze CPAN, Analyze Community
 
Annual Report 2012
Annual Report 2012Annual Report 2012
Annual Report 2012
 
DBD::SQLite
DBD::SQLiteDBD::SQLite
DBD::SQLite
 
CPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its toolsCPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its tools
 
CPANTS 2012
CPANTS 2012CPANTS 2012
CPANTS 2012
 
Revisiting ppm
Revisiting ppmRevisiting ppm
Revisiting ppm
 

Kürzlich hochgeladen

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 

Common boolean class_for_perl5

  • 1. Common Boolean Class for Perl 5 Kenichi Ishigaki @charsbar TPC in Glasgow 2018 Aug 16, 2018
  • 2. me • DBD::SQLite • CPANTS • PAUSE on Mojolicious • JSON/JSON::PP • Text::CSV/Text::CSV_PP
  • 3. Boolean is really simple It has only two states: TRUE or FALSE
  • 4. Boolean in Perl 5 is not that simple Because we don't have native boolean
  • 5. Typical implementation of boolean in Perl 5 my $true = 1; my $false = 0; $T = bless $true, $boolean_class; $F = bless $false, $boolean_class; (with some overload configuration)
  • 6. What if a "boolean" object is embedded in a string? • use overload to convert them into "true" or "false"? • ... if "$false"; # but true • say "This is " . ($bool->isa($boolean_class) ? ($bool ? "true" : "false") : $bool); # ugly
  • 7. How can you tell if it's a boolean? • MetaCPAN returns 1877 results when you search "Bool"... • Not all of them represent boolean, though...
  • 8. Don't worry too much All of them should work in the Perl context, at least as long as you use them in the boolean context
  • 9. Until you start serializing your data JSON modules only accept JSON::PP::Boolean objects (or their aliases) by default
  • 10. Luckily JSON::PP::Boolean is in Perl 5 core now • You can use it as a default boolean class • Do you want to use JSON::PP just to get boolean objects?
  • 11. How about boolean.pm? • It would have been nice if it were more widely adopted • Unfortunately it is not supported by JSON modules by default
  • 12. Or Types::Serialiser? • It provides boolean objects that are JSON::PP::Boolean • It has a more neutral name for CBOR::XS • It's not in core, so it's hard to adopt for toolchain modules or the likes
  • 13. Then what to do? • Add something into core? • Or just use the same convention under the hood? • Or else?
  • 14. The bottomline • The new stuff should work with existing modules • Otherwise you can't use it for interoperability
  • 16. bool.pm • Written by Tina Mueller as a proof of concept at PTS 2018 • Not yet CPANized https://github.com/perlpunk/bool-p5/tree/json-pp-compat
  • 17. Types::Bool • Written by Adriano Ferreira, inspired by Tina's PTS report • Works quite similar to Types::Serialiser https://metacpan.org/pod/Types::Bool
  • 18. There are still issues to be solved • bool namespace and Perl 6? • Types:: namespace is reserved for a different purpose? • duplicated effort? • and probably more
  • 19. Further reading • "My report of the Perl Toolchain Summit 2018 in Oslo" by Tina Mueller http://blogs.perl.org/users/tinita/2018/05/my-report-of-the- perl-toolchain-summit-2018-in-oslo.html • "[Work in Progress] Boolean support with Types::Bool" https://github.com/makamaka/JSON-PP/pull/36
  • 20. Let us know your thoughts