-
Notifications
You must be signed in to change notification settings - Fork 0
/
presentation.html
903 lines (532 loc) · 16.8 KB
/
presentation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
<!DOCTYPE html>
<html>
<head>
<title>Perl at PayProp</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
body { font-family: 'Droid Serif'; }
pre { font-size: 80%; }
h1, h2, h3 {
font-family: 'Yanone Kaffeesatz';
font-weight: normal;
}
img {
max-width: 90%;
display: block;
margin-left: auto;
margin-right: auto;
}
.remark-slide-content {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
</style>
</head>
<body>
<textarea id="source">
class: center, middle
![:scale 80%](img/qr_link.png)
???
This slides and all referenced talks are available here
---
class: center, middle
# Perl at PayProp
![:scale 40%](img/logo.png)
<br />
Lee Johnson (LEEJO / leejo / lee@payprop.com)
(Hit "P" for the notes and "?" for help)
???
A short talk about using Perl at an established company
Including the issues and challenges around that
And of course the good stuff
I gave this talk at FOSDEM back in February and i'll give it here from that point of view.
---
## About Me
Normally I don't do this...
???
(But, you know, imagine we're at FOSDEM)
Lots of faces I don't recognise so I'm sure lots of people that don't recognise me either...
--
* Senior Dev and Head of Processing at PayProp
???
Since 11 years, I'll get into that shortly
--
* Developer for 20 years
???
Worked with various languages, but most often Perl
Only worked for three companies in that time
So have seen tech stacks grow and change
--
* CPAN contributor: [LEEJO](https://metacpan.org/author/LEEJO)
???
--
* London and Swiss Perl Workshop organiser
???
Come and talk to me
--
* A regular [speaker](https://leejo.github.io/code/) at other Perl workshops and conferences
???
Usually helping out with recordings of talks
--
* An occasional [blogger](https://leejo.github.io/tags/perl/) on Perl
???
Prefer to write longer form articles than short technical posts
--
* Run the [Perl Events](https://www.instagram.com/perl_events/) Instagram account
???
That's pretty much the limit of my social media interaction however
--
* A FOSDEM newbie!
???
Our work event has always clashed, but not this year
---
## About PayProp
![payprop](img/payprop.png)
???
We're a payment and reconciliation platform for the residential lettings industry
---
## About PayProp
```sh
{1:F0110022136XXXX5294000001}
{4:
:20:FTT0047457610001
:25:000028078114
:28C:00001
:34F:CAD0,00
:13D:2312251501-0500
:61:2312271222C12841,47NTRF_//17
:86:PREAUTH CREDIT
BAM BAT1211 BUSINESS PAD
TN0102004200150561169205
-}
```
???
We automate their incoming and outgoing payment flow
Turning things like this
---
## About PayProp
![payprop](img/unreconciled.png)
???
Into things like this
We put interfaces and automation on time consuming payment flows
Saving customers hours or days of previously manual work
The keen eyed of you will see the cgi-bin in that URL...
We've been around for over 20 years so have some old code in places
---
## Which Perl?
--
* 5.32
???
We build our own
We don't do anything special there
We *could* in theory compile with special flags, but we don't
So we get the defaults, which means no ithreads (most Linux dists configure with threading enabled)
The key is that it's (next slide)
--
* Not the system Perl
???
So we're not tied to any particular version of the OS
Can apply security patches and updates as necessary
Yes we should be on 5.38 by now, but tend to trail a version
--
* Gives dependency control
???
This is critical
--
* Loose coupling
???
OS upgrades and migrations are much easier
--
* Everywhere!
???
DEV -> CI -> staging -> demo -> PROD
otherwise you're going to have problems
--
* Issues/Challenges?
* "You still use Perl?" (Hiring)
* "What is Perl?" (Hiring)
* Bus factor(s)
???
I'm sure you've encountered these as well
---
## CGI.pm -> Mojolicious
???
A 20 year app has some legacy
Bit of an understatement perhaps
--
* An ongoing task - about 2/3 complete
???
But it's a long tail
And we have some pages that will likely never be ported and will be turned off
Replaced by other newer pages / data warehouse stuff
--
* [Mojolicious::Plugin::CGI](https://metacpan.org/pod/Mojolicious::Plugin::CGI)
???
We used this in another platform but decided against it for PayProp
we're using apache anyway so just use that as a proxy for any non cgi-bin routes
--
* Static assets: Apache
* `/cgi-bin/`: Apache (`ExecCGI`)
* Anything else: proxy to Mojolicious server (`hypnotoad`)
--
* Previous talk: [Using Mojolicious For Fun & Non-Profit](http://leejo.github.io/using_mojolicious_for_fun_and_nonprofit/#/)
???
No video recording unfortunately
Written in 2014 and Mojolicious has moved on quite a bit
--
* Issues/Challenges?
* Mojolicious moves fast
* They don't do backwards compatibility
* Commit messages are very poor
???
although it's slowed down in the last couple of years
they claim "you can always count on backwards compatibility", but they have a 3 month deprecation window to change or *remove* features in non compatible ways. So, sorry, no you don't do backwards compatibility.
which compounds debugging attempts. a recent example (Aug 2023):
"Deprecate Mojo::File::spurt in favor of Mojo::File::spew"
- that's the *entire* commit message
- breaks backwards compatibility (when it's removed)
- i'm sure there's a massively compelling reason to rename a poorly named public method to another poor name, even though that's been in the framework since 2012
- so tell us why in the commit message *PLEASE*
- otherwise it's pointless churn that breaks other people's code
I should summarise this rant with the caveat that Mojolicious is still an excellent framework
---
## Adding an ORM
* I know this can be a contentious issue
???
Which i find surprising
--
* I'm tired of writing stuff like (simplified):
```perl
my $sql = "SELECT foo, bar, baz FROM property WHERE id = ?";
my $sth = $dbh->prepare_cached( $sql )
|| die "Can't prepare $sql: $DBI::errstr";
$sth->execute( $id );
if ( my $row = $sth->fetchrow_hashref ) {
say $row->{foo};
}
```
???
About the simplest use case you can have with DBI
--
* I much prefer:
```perl
if ( my $Property = $ORM->rs( 'Property' )->find( $id ) ) {
say $Property->foo;
}
```
???
I have no aversion to SQL
I just prefer not to code all the stuff we can get for free
If we need or want to drop down to vanilla SQL we can still do that
And we still do that for some of the more hairy queries
---
## Adding an ORM
* Allows us to address/hide some of the legacy issues in the schema:
* Polymorphic relationships
* Lack of foreign key constraints
* Poor choice of data types
* Confusing table/column names
???
Obviously this is a means to an end of eventually fixing the schema
And we need to keep the technical debt contained
--
* "Fix your underlying schema, things will break. Good. You might see it."
???
Stuff HN Says
"Might?"
Er, no - let's not risk a WFIO (google it) moment to satisfy an ideal
--
* Sure we could abstract that into our own libraries and modules
* But then we end up with a half done ORM
* Full of the bugs/issues other frameworks have already ironed out
???
But then we've just written our own ORM
We avoid Not-Invented Here as much as possible.
--
* We are using [DBIx::Class](https://metacpan.org/pod/DBIx::Class) as our ORM.
???
It's an feature rich and very flexible distribution
And it's not dogmatic about its use
--
* Issues/Challenges?
* Learning Curve
* Currently unmaintained
* Previous talk: [Battling a Legacy Schema With DBIx::Class](http://leejo.github.io/battling_a_legacy_schema_with_dbic/#/) ([Video](https://www.youtube.com/watch?v=ltckzIJYwHg))
???
ORMs are a paradigm shift
There's discussion to address the maintenance concern
A much longer talk with examples and tips
---
## Business Objects / Model
???
The older code is a procedural mashup of business logic, database access (SQL), view logic (via custom templates), and so on
The newer code is factored into business objects
Note that *THIS* is our model, the ORM is *NOT* our model
--
* Classes
* Abstract
* Derived (polymorphism / inheritance)
* Composition (roles)
* Attribute...
* Type Constraints
* Type Coercion
* Defaults
* Triggers
* Etc...
* Encapsulation
* Immutable state
* Delegation
* Meta Object Protocol (MOP)
* Tell, Don't Ask
???
All this is useful stuff and very powerful
OO done properly
--
* [Moose](https://metacpan.org/pod/Moose)
* [Corinna](https://ovid.github.io/articles/corinna-in-the-perl-core.html) (eventually)
???
We're using Moose (and previously Mouse) for our object framework
Corinna we will look to use once it's more feature rich. Ovid will talk about Croinna a little later.
---
## Business Objects / Model
```perl
package PayProp::Model::Payment::Incoming;
...
has [ qw/ statement reversal / ] => (
is => 'ro',
isa => 'BankStatement',
required => 0,
);
```
???
As an example we have an incoming payment object with attributes
One of which is a BankStatement object
--
```perl
subtype 'BankStatement'
=> as 'Object'
=> where {
$_->has_id
&& (
$_->isa( 'PayProp::Model::BankStatement' )
|| $_->isa( 'PayProp::Model::BankStatement::Internal' )
);
}
=> message { $_
? ( $_ . " lacks an id" )
: "BankStatement is not defined"
}
;
```
???
Which we can constrain as this particular type
---
## Business Objects / Model
```perl
sub fail_payment ( $self ) {
# some state checking
if ( ! $self->can_be_failed ) {
PayProp::Exception::State->throw(
"Cannot fail payment because....."
)
}
...
if ( my $BankStatement = $self->statement ) {
$BankStatement->mark_failed;
}
...
}
```
???
Tell don't ask
---
## Business Objects / Model
* [Moose](https://metacpan.org/pod/Moose)
* Issues/Challenges?
* Learning curve
* Slow startup in a non persistent environment?
* CGI scripts
* Command line
* Mutable state in earlier code
???
The learning curve is worth it, Moose is one of the best object systems available across any language. Adding the MOP (meta object protocol) and the Perl's own introspection features makes it incredibly powerful.
There have been multi day courses at Perl conferences in the past dedicated to Moose. It's impossible for me to even even scratch the surface in this talk
lazy loading for CGI scripts, the command line - live with it, they're run once in a blue moon scripts anyway
Mutable state is my technical debt
---
## Refactoring / Regression Testing
--
* Beyond unit and integration testing
???
We have this for all new code and add to existing code prior to refactoring
Where possible...
--
* Critical business scripts that have existed forever
* We want minimal risk when updating/fixing/refactoring
* Bootstrapping problem:
* Not in a state to allow automated testing
* Need to change them to fix that
* But that is a risk without automated testing
--
* But this is Perl!
* Introspection and side loading of overrides
* Run scripts with override library paths
* Hook into various compile/runtime blocks
---
## Refactoring / Regression Testing
```perl
package Override::SomeScript;
use strict;
use warnings;
INIT {
no warnings 'redefine';
# read_text and read_dir are imported into the main namespace so we override
# them there and not in File::Slurper. here we return the "passphrase"
*main::read_text = sub {
return "it's the end of August and we have no AC in the office :(";
};
};
```
--
```perl
my $overrides = "-I$Bin/t/olib/ -MOverride::SomeScript";
my $cron_script = "some_script.pl";
test_command(
'cron script runs (overrides)',
"/path/to/our/perl $overrides $cron_script",
...
```
---
## Refactoring / Regression Testing
* More info: [talk by Nicholas Clark](https://www.youtube.com/watch?v=gJPbuNtH8aQ)
???
45min talk going into the details
--
* Issues/Challenges?
* This approach adds more technical debt
* Load order/action at a distance (end up debugging the *tests*)
???
get the script fully tested
refactor to a easier testable state (i.e. modules)
convert these tests to unit tests
---
## Contributing to CPAN
![:scale 75%](img/CPAN.png)
???
We actively encourage contributions to CPAN.
These are all distributions we have either written or taken over maintenance of in the last decade
---
## Contributing to CPAN
???
Stuff like
--
* Mojolicious Plugins
* Mojolicious::Plugin::NYTProf
* Mojolicious::Plugin::OAuth2::Server
* Net::OAuth2::AuthorizationServer
--
* Third Party Payment API Libraries
* Business::GoCardless
* Business::TrueLayer
* Business::Monzo
* Business::Fixflo
--
* And other stuff
???
maintaining CGI.pm
forking and updating unmaintained API libraries
--
* Issues/Challenges?
* The pool of contributors to CPAN is shrinking
* Libraries for newer services and APIs don't exist
* Navigating around IP issues to get code uploaded
???
Solution - we volunteer to maintain existing distributions
We write libraries for newer services and APIs and upload them to CPAN
Many modern APIs are RESTful so it's trivial to create a library for them
IP concerns encourages us to properly decouple our code from the library code
---
## Hiring Devs New to Perl
* Perl has been on the plateau of productivity for quite a while
--
* Those that left Perl a long time ago don't know the current ecosystem
--
* We're more than a generation removed from even Perl 5
--
* Perl 1 was released in 1987 <- 37 years ago.
* Perl 5 was released in 1994 <- 30 years ago.
* Perl 5.10 was released in 2007 <- 17 years ago.
???
5.10 being "modern" Perl
--
* Perl is still in a lot of places
???
Some of these places the users can't talk about in public forum like this. Banks, the FANGS. If you're working for a company that won't let you talk about Perl, or you've simply never thought about doing that - ask and do.
the rumors of Perl's demise I think are greatly exaggerated, but it's a known unknown at this point. Speak up.
It's still being used for greenfield projects. The system FOSDEM are using to review, annotate, cut, process, transcode, and publish all their videos (almost one thousand videos this weekend) is written in Modern Perl - https://github.com/yoe/SReview
--
* Its popularity normalised over the last two decades
???
Hate to cite it, as I their methodology is poor, but the TIOBE index shows the trend of *all* programming language use steadily approaching a homogenized state. That's probably a good thing - monoculture should be avoided
--
* So it's hard to find "Perl developers". But...
--
* Newcomers don't have preconceptions
---
## Hiring Devs New to Perl
* Newcomers don't have preconceptions?
???
is my experience of interviewing
generally those under 30 either haven't heard of the language
or haven't used it
those who don't want to use the language or don't like it self select out of the hiring process
we are explicit in job specs that we use Perl
but we don't list it as a requirement unless we're asking for a senior Perl developer
--
* Modern Perl is a interesting and enjoyable language to work with
* Working with legacy code is a reality
* That's in no way unique to Perl
--
* Mentoring
* Code Review
* Workshops
* Developer Conferences
* Weekly Show-and-Tell / Talks
???
We do all of this, it's essential if you have newcomers to the language - especially for Perl. The web is full of a lot of out of date advice and examples.
--
* More info: [blog posts](https://leejo.github.io/tags/perl/)
???
I haven't really talked about this previously, but have written a few blog posts that touch upon it
--
* You can be very experienced but still a newcomer
* That's absolutely fine
* In fact, it's beneficial to the ecosystem and community
???
So speak up, we want to hear from you.
---
## Questions? / References
![qr_code_link](img/qr_link.png)
This talk is available at: (https://leejo.github.io/code/)
* [PayProp](https://www.payprop.com)
* [We Are Hiring!](https://careers.payprop.com/)
</textarea>
<script src="https://remarkjs.com/downloads/remark-latest.min.js" type="text/javascript">
</script>
<script type="text/javascript">
remark.macros['scale'] = function (percentage) {
var url = this;
return '<center><img src="' + url + '" style="width: ' + percentage + '" /></center>';
};
var slideshow = remark.create({
highlightLines: true,
//slideNumberFormat: ""
});
</script>
</body>
</html>