LinkSite/Site.pm

filter: Statementstmt 89.7% 35 / 39 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 90.0% 45 / 50 CC 2 SCAR 2.9
CC
2
Cov
90%
all_links
2.0
json_ld
2.0
BEGIN
1.0
CRAP 1.3
« LinkSite/Link.pm ↑ Summary LinkSite/Section.pm »
1 =head1 NAME
2  
3 App::LinkSite::Site
4  
5 =head1 SYNOPIS
6  
7 (You probably want to just look at the L<linksite> application.)
8  
9 =head1 DESCRIPTION
10  
11 A class to model a link site (part of App::LinkSite).
12  
13 =cut
14  
15 2 ▶use Feature::Compat::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 class App::LinkSite::Site {
18 2 our $VERSION = '0.1.3';
19 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ no if $] >= 5.038, 'warnings', 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶ use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 field $name :reader :param;
26 2 field $handle :reader :param;
27 2 field $image :reader :param;
28 2 field $desc :reader :param;
29 2 field $og_image :reader :param;
30 2 field $site_url :reader :param;
31 2 field $text_color :reader :param = undef;
32 2 field $background_color :reader :param = undef;
33  
34 2 field $socials :reader :param = [];
35 2 field $links :reader :param = [];
36 2 field $sections :reader :param = [];
37  
38 =head1 METHODS
39  
40 =head2 has_sections
41  
42 Returns true if the site has any non-empty sections.
43  
44 =cut
45  
46 2 ▶ method has_sections {
Subroutine has_sections: called CC=1 SCAR=0.0
Pod documented
47 2 return scalar(grep { $_->has_links } $self->sections->@*) > 0;
48 }
49  
50 =head2 all_links
51  
52 Returns all links from both the links array and all sections.
53  
54 =cut
55  
56 1 ▶ method all_links {
Subroutine all_links: called CC=2 SCAR=6.9
Pod documented
57 1 my @all_links = $self->links->@*;
58 1 for my $section ($self->sections->@*) {
59 2 push @all_links, $section->links->@*;
60 }
61 1 return @all_links;
62 }
63  
64 =head2 json_ld
65  
66 Returns a JSON/LD fragment for this web site.
67  
68 =cut
69  
70 0 ▶ method json_ld {
Subroutine json_ld: not called CC=1 SCAR=6.9
Pod documented
71 my $json = {
72 '@context' => 'https://schema.org',
73 '@type' => 'WebPage',
74 name => "Links page for $name ($handle)",
75 mainEntity => {
76 '@context' => 'https://schema.org',
77 '@type' => 'Person',
78 name => $self->name,
79 image => $self->image,
80 0 sameAs => [ map { $_->mk_social_link } $self->socials->@* ],
81 },
82 0 relatedLink => [ map { $_->link } $self->all_links ],
83 };
84  
85 0 return JSON->new->pretty->encode($json);
86 }
87 }
88  
89 2 1;
90  
91 =head1 AUTHOR
92  
93 Dave Cross <dave@davecross.co.uk>
94  
95 =head1 COPYRIGHT AND LICENCE
96  
97 Copyright (c) 2024, Magnum Solutions Ltd. All Rights Reserved.
98  
99 This library is free software; you can redistribute it and/or modify it
100 under the same terms as Perl itself.
101  
102 =cut
« LinkSite/Link.pm ↑ Summary LinkSite/Section.pm »